Feature | Syntax | Description | Example | .NET | Java | Perl | PCRE | PCRE2 | PHP | Delphi | R | JavaScript | VBScript | XRegExp | Python | Ruby | std::regex | Boost | Tcl ARE | POSIX BRE | POSIX ERE | GNU BRE | GNU ERE | Oracle | XML | XPath |
Mode modifier |
(?letters) at the start of the regex |
A mode modifier at the start of the regex affects the whole regex and overrides any options set outside the regex. |
(?i)a matches a and A . |
YES | YES | YES | YES | YES | YES | YES | YES | no | no | YES | YES | YES | no | ECMA | YES | no | no | no | no | no | no | no |
Mode modifier |
(?letters) in the middle of the regex |
A mode modifier in the middle of the regex affects the whole regex and overrides any options set outside the regex. |
te(?i)st matches test , teST , TEst and TEST . |
no | no | no | no | no | no | no | no | no | no | no | YES | no | no | no | no | no | no | no | no | no | no | no |
Mode modifier |
(?letters) in the middle of the regex |
A mode modifier in the middle of the regex affects only the part of the regex to the right of the modifier. If the modifier is used inside a group, it only affects the part of the regex inside that group to the right of the modifier. If the regex or group uses alternation, all alternatives to the right of the modifier are affected. |
te(?i)st matches test and teST but not TEst or TEST . |
YES | YES | YES | YES | YES | YES | YES | YES | no | no | no | no | YES | no | ECMA | no | no | no | no | no | no | no | no |
Modifier group |
(?letters:regex) |
Non-capturing group with modifiers that affect only the part of the regex inside the group. |
te(?i:st) matches test and teST but not TEst or TEST . |
YES | YES | YES | YES | YES | YES | YES | YES | no | no | no | 3.6 | YES | no | ECMA | no | no | no | no | no | no | no | no |
Negative modifier |
(?on-off) and (?on-off:regex) |
Modifier letters (if any) before the hyphen are turned on, while modifier letters after the hyphen are turned off. |
(?i)te(?-i)st matches test and TEst but not teST or TEST . |
YES | YES | YES | YES | YES | YES | YES | YES | n/a | n/a | no | 3.6 | YES | n/a | ECMA | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Reset modifiers |
(?^) |
Turn off all options. The caret can be followed by modifier letters to turn some options back on. |
(?i)te(?^)st matches test and TEst but not teST or TEST . |
no | no | 5.14 | no | 10.32 | 7.3.0 | no | 4.0.0 | n/a | n/a | no | no | no | n/a | no | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Case insensitive |
(?i) |
Turn on case insensitivity. |
(?i)a matches a and A . |
YES | YES | YES | YES | YES | YES | YES | YES | n/a | n/a | YES | YES | YES | n/a | ECMA | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Case sensitive |
(?c) |
Turn on case sensitivity. |
(?c)a matches a but not A . |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Free-spacing |
(?x) |
Turn on free-spacing mode to ignore whitespace between regex tokens and allow # comments. |
(?x)a matches a |
YES | YES | YES | YES | YES | YES | YES | YES | n/a | n/a | YES | YES | YES | n/a | ECMA | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Free-spacing |
(?xx) |
Turn on free-spacing mode to ignore whitespace between regex tokens and allow # comments, both inside and outside character classes. |
(?xx)[ a] matches a but not |
no | no | 5.26 | no | 10.30 | 7.3.0 | no | 4.0.0 | n/a | n/a | no | no | no | n/a | no | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Exact spacing |
(?t) |
Turn on “tight” or exact spacing mode to treat whitespace and # characters as literals. |
(?t)a#b matches a#b |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Single-line |
(?s) |
Make the dot match all characters including line break characters. |
(?s).* matches ab\n\ndef in ab\n\ndef |
YES | YES | YES | YES | YES | YES | YES | YES | n/a | n/a | YES | YES | no | n/a | ECMA | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Multi-line |
(?m) |
Make ^ and $ match at the start and end of each line. |
(?m)^. matches a and d in ab\n\ndef |
YES | YES | YES | YES | YES | YES | YES | YES | n/a | n/a | YES | YES | no | n/a | ECMA | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Single-line |
(?m) |
Make the dot match all characters including line break characters. |
(?m).* matches ab\n\ndef in ab\n\ndef |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | YES | n/a | no | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Tcl single-line |
(?s) |
Make ^ and $ match at the start and end of the string only. Make the dot match all characters including line break characters. |
(?s)^.{3} matches only ab\n in ab\n\ndef |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Tcl multi-line |
(?m) |
Make ^ and $ match at the start and end of each line. Do not allow the dot and negated character classes to match line break characters. |
(?m)^. matches a and d in ab\n\ndef |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Tcl multi-line |
(?n) |
Make ^ and $ match at the start and end of each line. Do not allow the dot and negated character classes to match line break characters. |
(?n)^. matches a and d in ab\n\ndef |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Tcl “partial” newline-sensitive |
(?p) |
Make ^ and $ match at the start and end of the string only. Do not allow the dot and negated character classes to match line break characters. |
(?p)^.* matches only ab in ab\n\ndef |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Tcl “weird” newline-sensitive |
(?w) |
Make ^ and $ match at the start and end of each line. Make the dot match all characters including line break characters. |
(?w)^. matches a , the first \n , and d in ab\n\ndef |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Explicit capture |
(?n) |
Plain parentheses are non-capturing groups instead of numbered capturing groups. Only named capturing groups actually capture. |
(?n)(a|b)c is the same as (?:a|b)c |
YES | no | 5.22 | no | 10.30 | 7.3.0 | no | 4.0.0 | n/a | n/a | YES | no | no | n/a | no | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Duplicate named groups |
(?J) |
Allow multiple named capturing groups to share the same name. |
(?J)(?:(?'x'a)|(?'x'b))\k'x' matches aa or bb |
no | no | no | 6.7 | YES | 5.2.0 | YES | YES | n/a | n/a | no | no | no | n/a | no | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Ungreedy quantifiers |
(?U) |
Switches the syntax for greedy and lazy quantifiers. Its use is strongly discouraged because it confuses the meaning of the standard quantifier syntax. |
(?U)a* is lazy and (?U)a*? is greedy |
no | no | no | YES | YES | YES | YES | YES | n/a | n/a | no | no | no | n/a | no | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
UNIX lines |
(?d) |
When anchors match at line breaks and when the dot does not match line breaks, make them recognize only the line feed character as a line break |
(?dm)^. matches a and c in a\rb\nc |
no | YES | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
BRE |
(?b) |
Interpret the regular expression as a POSIX BRE |
(?b)a\+ matches aaa |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
ERE |
(?e) |
Interpret the regular expression as a POSIX ERE |
(?e)[a\]+ matches a\a\a |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Literal |
(?q) |
Interpret the regular expression as a literal string (excluding the modifier) |
(?q)[a\]+ matches [a\]+ literally |
no | no | no | no | no | no | no | no | n/a | n/a | no | no | no | n/a | no | YES | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Extra syntax |
(?X) |
Treat letters that are escaped with a backslash and that don’t form a regex token as an error instead of as a literal. |
(?X)\q is an error while (?-X)\q matches q |
no | no | no | YES | no | 5.0.0–7.2.34 | YES | 2.14.0–3.6.3 | n/a | n/a | no | no | no | n/a | no | no | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
Feature | Syntax | Description | Example | .NET | Java | Perl | PCRE | PCRE2 | PHP | Delphi | R | JavaScript | VBScript | XRegExp | Python | Ruby | std::regex | Boost | Tcl ARE | POSIX BRE | POSIX ERE | GNU BRE | GNU ERE | Oracle | XML | XPath |
---|