Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
gmx

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "^\n" + "(?=[-+]?(?:0\\B)*+(\\d*?)((?:(?=\\d+(?:\\.\\d+)?\\ [-+]?(?:0\\B)*+(\\d*?)(\\d(?(4)\\4))(?:\\.\\d+)?\\ [-+]?(?:0\\B)*+(\\d*?)(\\d(?(6)\\6))(?:\\.\\d+)?$)\\d)++)\\b)\n" + "(?:\n" + " (?=-\\S*\\ -\\S*\\ -|(?!.*-))\n" + " [-+]?(?:0\\B)*+\n" + " (?=\n" + " (?(?!\\1\\.?(?!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\\g\\{-1\\}7|4\\g\\{-1\\}6|5\\g\\{-1\\}5|6\\g\\{-1\\}4|7\\g\\{-1\\}3|8\\g\\{-1\\}2|9\\g\\{-1\\}1)\n" + " \\d0*\\ [-+]?0*\\3\\15\\g\\{-2\\}?+\\.?\\d0*\\ [-+]?0*\\5\\17\\.?0*$\n" + " )\n" + "|\n" + " (?=-(?!.*-)|[^-]\\S*\\ -\\S*\\ -)\n" + " [-+]?(?:0\\B)*+\n" + " (?=\n" + " (?(?!\\1\\.?(?!(?!(?&c))))\n" + " (?=\\S+\\ [-+]?0*\\1\\5\\4\\b)\n" + " \n" + " |\n" + " (?|\n" + " (?!.++\\5)\n" + " \\S+\\ [-+]?(?:0\\B)*+(?=\\S*(\\ [-+]?(?:0\\B)*+)())\n" + " (?(?=\\S*\\41[9]*\\6\\b)\n" + " 1(?:0(?=\\S*\\41(\\g\\{-1\\}?+9)))*?\n" + " \\4\\b\\S*\\41\\g\\{-1\\}?+\\6\\b\n" + " |\n" + " (?:(\\d)(?=\\S*\\41(\\g\\{-1\\}?+\\g\\{-2\\})))*+\n" + " (?=\\d(\\S*\\41\\g\\{-2\\}?+))(?=1\\g\\{-1\\}0|2\\g\\{-1\\}1|3\\g\\{-1\\}2|4\\g\\{-1\\}3|5\\g\\{-1\\}4|6\\g\\{-1\\}5|7\\g\\{-1\\}6|8\\g\\{-1\\}7|9\\g\\{-1\\}8)\n" + " \\d\n" + " (?:0(?=\\S*\\41\\g\\{-2\\}?+\\d(\\g\\{-1\\}?+9)))*?\n" + " \\4\\b\\S*\\41\\g\\{-3\\}?+\\d\\g\\{-1\\}?+\\6\\b\n" + " )\n" + " |\n" + " (?=.*+\\5)\n" + " (?=\\d*?(\\2)\\b(\\S*\\ [-+]?(?:0\\B)*+))\n" + " \n" + " (?(?=9*\\41\\b)\n" + " (?:9(?=\\d*?\\42[1](\\g\\{-1\\}?+0)))*?\n" + " \\41\\42[1]\\g\\{-1\\}?+\\4\\b\n" + " |\n" + " (?:(\\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]?(?:0\\B)*+\n" + " (?=\n" + " (?(?!\\S+\\ [-+]?(?:0\\B)*+\\3\\.?(?!(?!(?&e))))\n" + " (?=\\3\\5\\2\\b)\n" + " |\n" + " (?=\\d*(\\S*\\ (?(?=.*+\\3)\\S+\\ )[-+]?(?:0\\B)*+)\\d*?(\\4|\\6)\\b)\n" + " (?(?=10*\\2\\b)\n" + " 1(?:0(?=\\d*\\75(\\g\\{-1\\}?+9)))*?\n" + " \\2\\b\\75\\g\\{-1\\}?+\\76\\b\n" + " |\n" + " (?:(\\d)(?=\\d*\\75(\\g\\{-1\\}?+\\g\\{-2\\})))*+\n" + " (?=\\d(\\d*\\75\\g\\{-2\\}?+))\n" + " (?=1\\g\\{-1\\}0|2\\g\\{-1\\}1|3\\g\\{-1\\}2|4\\g\\{-1\\}3|5\\g\\{-1\\}4|6\\g\\{-1\\}5|7\\g\\{-1\\}6|8\\g\\{-1\\}7|9\\g\\{-1\\}8)\n" + " \\d\n" + " (?:0(?=\\d*\\75\\g\\{-2\\}?+\\d(\\g\\{-1\\}?+9)))*?\n" + " \\2\\b\\75\\g\\{-3\\}?+\\d\\g\\{-1\\}?+\\76\\b\n" + " )\n" + " )\n" + " )\n" + " \\1\n" + " (?:\n" + " (?=\\.?(\\d)\\S*\\ [-+]?(?:0\\B)*+\\3((\\g\\{-2\\}?+\\.?)\\d)\\S*\\ [-+]?(?:0\\B)*+\\5((\\g\\{-2\\}?+\\.?)\\d))\n" + " \\.?\n" + " (?(?=(?!\n" + " \\S*\\ [-+]?(?:0\\B)*+\\3\\83\\.?\n" + " (?<e>\n" + " (?:\n" + " (?=\\d\\.?\\d(?<f>\\S*?\\ [-+]?(?:0\\B)*\\5\\85?+)((\\g\\{-2\\}?+\\.?)\\d))\n" + " (?=\\d(\\S*?\\g\\{-4\\}\\g\\{-2\\}))\n" + " (?=0\\g\\{-1\\}9|1\\g\\{-1\\}8|2\\g\\{-1\\}7|3\\g\\{-1\\}6|4\\g\\{-1\\}5|5\\g\\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)*+\n" + " (?=\\d(\\g\\{-3\\}|(?&f)\\.?))\n" + " (?=1\\g\\{-1\\}9|2\\g\\{-1\\}8|3\\g\\{-1\\}7|4\\g\\{-1\\}6|5\\g\\{-1\\}5|6\\g\\{-1\\}4|7\\g\\{-1\\}3|8\\g\\{-1\\}2|9\\g\\{-1\\}1)\n" + " \\d0*\\ [-+]?0*\\5\\85\\g\\{-2\\}?+\\.?\\d0*$\n" + " ) \n" + ")"; final String string = "0 0 0\n" + "-1 0 -1\n" + "1 0 -1\n" + "-1 100 99\n" + "1 99 1000\n" + "-10.000 0.0001 -9.9999\n" + "-234434.943279 9099898.9044 8865463.961121"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.COMMENTS); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html