Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
^(?=^([^)(]*\(((?>[^)(]+)|(?1))*\)[^)(]*)*$)(?=^([^][]*\[((?>[^][]+)|(?3))*\][^][]*)*$)(?=^([^}{]*\{((?>[^}{]+)|(?5))*\}[^}{]*)*$)(?!^\(.*)(?!.*\(.{250}\).*)(?=.*\[.{250}\].*)(?=.*\{.{250}\}.*)(?=.*\[.\(\).\{\}.\].*)(?=.*\}...\[...\[...\]...\]...\{.*)(?=.*\(\(..\(\(.{68}\(\(\)\).{43}\)\)\)\).*)(?=.*\{..\{..\{.{65}\{\}\{\}.{33}\{\}.{107}\}\}.\}.*)(?=.*\[\{\{\[\(\{.*)(?=.*\[\[..\[.{6}\[.{6}\]\]...\]\].{6}\[..\]..\[\].*)(?=.*\]\]\}\}\}.\)\)\)\).{96}\]\}\}\]\]\]\}\]\]\].\)\]\].*)(?=.*\]..\).{6}\(.{7}\{.{5}\[...\[.{5}\{\[.*)(?=.*\[.{87}\{.{45}}{.{38}}.{27}\].*)(?=.*\(\{.{32}\(.{20}\{.{47}\].{43}\{\{.{25}\}\}.{18}\].{5}\}....\}.{5}\).*)(?=.*\{.{12}\(.{5}\(...\(...\{\[.\{\[\[.*)(?=.*\{\(.{21}\).{8}\}.{14}\[.{7}\]..\{.{5}\{\}....\}.*)(?=.*\(.\{.{49}\{.{16}\}.{25}\}.{66}\).*)(?!.*\(\{\(\(.*)(?!.*\(\)\[\].*)(?=(.*?\].*?\)){15,}.*)(?=(.*\[.*\(.*\{){5,9}.*)(?=.*\({3}.{105}\[{3}.{105}[^}{].*)(?=.*\(..\).{5}\(\)....\}\}\].\{\{\[.{22}\[.{35}\}\}\].*)(?!.*\(\(.{178}\])(?=(.*\[..\]){8,10}.*)(?!(.*\([^\(\)]{5}\(){4,}.*).{63}(.{6}).{130}\11.{51}$
/
^ asserts position at start of the string
Positive Lookahead
(?=^([^)(]*\(((?>[^)(]+)|(?1))*\)[^)(]*)*$)
Assert that the Regex below matches
^ asserts position at start of the string
1st Capturing Group
([^)(]*\(((?>[^)(]+)|(?1))*\)[^)(]*)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
Match a single character not present in the list below
[^)(]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
)(
matches a single character in the list )( (case sensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
2nd Capturing Group
((?>[^)(]+)|(?1))*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
1st Alternative
(?>[^)(]+)
Atomic Group
(?>[^)(]+)
Non-capturing group that discards backtracking positions once matched.
Match a single character not present in the list below
[^)(]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
)(
matches a single character in the list )( (case sensitive)
2nd Alternative
(?1)
(?1) recurses the 1st subpattern
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
Match a single character not present in the list below
[^)(]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
)(
matches a single character in the list )( (case sensitive)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Positive Lookahead
(?=^([^][]*\[((?>[^][]+)|(?3))*\][^][]*)*$)
Assert that the Regex below matches
^ asserts position at start of the string
3rd Capturing Group
([^][]*\[((?>[^][]+)|(?3))*\][^][]*)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
Match a single character not present in the list below
[^][]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
][
matches a single character in the list ][ (case sensitive)
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
4th Capturing Group
((?>[^][]+)|(?3))*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
1st Alternative
(?>[^][]+)
Atomic Group
(?>[^][]+)
Non-capturing group that discards backtracking positions once matched.
Match a single character not present in the list below
[^][]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
][
matches a single character in the list ][ (case sensitive)
2nd Alternative
(?3)
(?3) recurses the 3rd subpattern
\] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
Match a single character not present in the list below
[^][]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
][
matches a single character in the list ][ (case sensitive)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Positive Lookahead
(?=^([^}{]*\{((?>[^}{]+)|(?5))*\}[^}{]*)*$)
Assert that the Regex below matches
^ asserts position at start of the string
5th Capturing Group
([^}{]*\{((?>[^}{]+)|(?5))*\}[^}{]*)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
Match a single character not present in the list below
[^}{]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
}{
matches a single character in the list }{ (case sensitive)
\{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
6th Capturing Group
((?>[^}{]+)|(?5))*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
1st Alternative
(?>[^}{]+)
Atomic Group
(?>[^}{]+)
Non-capturing group that discards backtracking positions once matched.
Match a single character not present in the list below
[^}{]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
}{
matches a single character in the list }{ (case sensitive)
2nd Alternative
(?5)
(?5) recurses the 5th subpattern
\} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
Match a single character not present in the list below
[^}{]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
}{
matches a single character in the list }{ (case sensitive)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Negative Lookahead
(?!^\(.*)
Assert that the Regex below does not match
^ asserts position at start of the string
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?!.*\(.{250}\).*)
Assert that the Regex below does not match
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
.
matches any character (except for line terminators)
{250} matches the previous token exactly 250 times
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=.*\[.{250}\].*)
Assert that the Regex below matches
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
.
matches any character (except for line terminators)
{250} matches the previous token exactly 250 times
\] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=.*\{.{250}\}.*)
Assert that the Regex below matches
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
.
matches any character (except for line terminators)
{250} matches the previous token exactly 250 times
\} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=.*\[.\(\).\{\}.\].*)
Assert that the Regex below matches
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
. matches any character (except for line terminators)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
. matches any character (except for line terminators)
\{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
\} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
. matches any character (except for line terminators)
\] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=.*\}...\[...\[...\]...\]...\{.*)
Assert that the Regex below matches
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
\] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
\] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
\{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=.*\(\(..\(\(.{68}\(\(\)\).{43}\)\)\)\).*)
Assert that the Regex below matches
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
.
matches any character (except for line terminators)
{68} matches the previous token exactly 68 times
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
.
matches any character (except for line terminators)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
.
matches any character (except for line terminators)
Positive Lookahead
(?=.*\{..\{..\{.{65}\{\}\{\}.{33}\{\}.{107}\}\}.\}.*)
Assert that the Regex below matches
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
\{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
. matches any character (except for line terminators)
. matches any character (except for line terminators)
\{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
.
matches any character (except for line terminators)
\{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
\} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
\{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
\} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
.
matches any character (except for line terminators)
\{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
\} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
.
matches any character (except for line terminators)
\} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
\} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
. matches any character (except for line terminators)
\} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
.
matches any character (except for line terminators)
Positive Lookahead
(?=.*\[\{\{\[\(\{.*)
Assert that the Regex below matches
Positive Lookahead
(?=.*\[\[..\[.{6}\[.{6}\]\]...\]\].{6}\[..\]..\[\].*)
Assert that the Regex below matches
Positive Lookahead
(?=.*\]\]\}\}\}.\)\)\)\).{96}\]\}\}\]\]\]\}\]\]\].\)\]\].*)
Assert that the Regex below matches
Positive Lookahead
(?=.*\]..\).{6}\(.{7}\{.{5}\[...\[.{5}\{\[.*)
Assert that the Regex below matches
Positive Lookahead
(?=.*\[.{87}\{.{45}}{.{38}}.{27}\].*)
Assert that the Regex below matches
Positive Lookahead
(?=.*\(\{.{32}\(.{20}\{.{47}\].{43}\{\{.{25}\}\}.{18}\].{5}\}....\}.{5}\).*)
Assert that the Regex below matches
Positive Lookahead
(?=.*\{.{12}\(.{5}\(...\(...\{\[.\{\[\[.*)
Assert that the Regex below matches
Positive Lookahead
(?=.*\{\(.{21}\).{8}\}.{14}\[.{7}\]..\{.{5}\{\}....\}.*)
Assert that the Regex below matches
Positive Lookahead
(?=.*\(.\{.{49}\{.{16}\}.{25}\}.{66}\).*)
Assert that the Regex below matches
Negative Lookahead
(?!.*\(\{\(\(.*)
Assert that the Regex below does not match
Negative Lookahead
(?!.*\(\)\[\].*)
Assert that the Regex below does not match
Positive Lookahead
(?=(.*?\].*?\)){15,}.*)
Assert that the Regex below matches
Positive Lookahead
(?=(.*\[.*\(.*\{){5,9}.*)
Assert that the Regex below matches
Positive Lookahead
(?=.*\({3}.{105}\[{3}.{105}[^}{].*)
Assert that the Regex below matches
Positive Lookahead
(?=.*\(..\).{5}\(\)....\}\}\].\{\{\[.{22}\[.{35}\}\}\].*)
Assert that the Regex below matches
Negative Lookahead
(?!.*\(\(.{178}\])
Assert that the Regex below does not match
Positive Lookahead
(?=(.*\[..\]){8,10}.*)
Assert that the Regex below matches
Negative Lookahead
(?!(.*\([^\(\)]{5}\(){4,}.*)
Assert that the Regex below does not match
.
matches any character (except for line terminators)
11th Capturing Group
(.{6})
.
matches any character (except for line terminators)
\11 matches the same text as most recently matched by the 11th capturing group
.
matches any character (except for line terminators)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/

Test String

Code Generator

Generated Code

Loading code sample...
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php