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
/
^(?3)*\)*$(()((?(2)|\)*)(\((?1)*(\)|$)|0|"[^\n"]*.?|(1|(2|(3|4(?3))(?3))(?3))(?3))))?
/
gm
^ asserts position at start of a line
(?3)
recurses the 3rd subpattern
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\)
matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
$ asserts position at the end of a line
1st Capturing Group
(()((?(2)|\)*)(\((?1)*(\)|$)|0|"[^\n"]*.?|(1|(2|(3|4(?3))(?3))(?3))(?3))))?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Capturing Group
()
null, matches any position
3rd Capturing Group
((?(2)|\)*)(\((?1)*(\)|$)|0|"[^\n"]*.?|(1|(2|(3|4(?3))(?3))(?3))(?3)))
Conditional
(?(2)|\)*)
Conditionally matches one of two options depending on whether the 2nd capturing group matched
If condition is met, match the following regex null, matches any position
Else match the following regex
\)*
\)
matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
4th Capturing Group
(\((?1)*(\)|$)|0|"[^\n"]*.?|(1|(2|(3|4(?3))(?3))(?3))(?3))
1st Alternative
\((?1)*(\)|$)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
(?1)
recurses the 1st subpattern
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
5th Capturing Group
(\)|$)
1st Alternative
\)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
2nd Alternative
$
$ asserts position at the end of a line
2nd Alternative
0
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
3rd Alternative
"[^\n"]*.?
" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
Match a single character not present in the list below
[^\n"]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
4th Alternative
(1|(2|(3|4(?3))(?3))(?3))(?3)
6th Capturing Group
(1|(2|(3|4(?3))(?3))(?3))
1st Alternative
1
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
2nd Alternative
(2|(3|4(?3))(?3))(?3)
7th Capturing Group
(2|(3|4(?3))(?3))
1st Alternative
2
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
2nd Alternative
(3|4(?3))(?3)
8th Capturing Group
(3|4(?3))
1st Alternative
3
3 matches the character 3 with index 5110 (3316 or 638) literally (case sensitive)
2nd Alternative
4(?3)
4 matches the character 4 with index 5210 (3416 or 648) literally (case sensitive)
(?3) recurses the 3rd subpattern
(?3) recurses the 3rd subpattern
(?3) recurses the 3rd subpattern
(?3) recurses the 3rd subpattern
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gm

Test String