Regular Expressions 101

Save & Share

Flavor

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

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
(?:"(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?|([\{\}\[\]]))
/
g
Non-capturing group
(?:"(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?|([\{\}\[\]]))
1st Alternative
"(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?
" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
1st Capturing Group
(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*
* 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
\\u[a-zA-Z0-9]{4}
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
u matches the character u with index 11710 (7516 or 1658) literally (case sensitive)
Match a single character present in the list below
[a-zA-Z0-9]
{4} matches the previous token exactly 4 times
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
2nd Alternative
\\[^u]
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
Match a single character not present in the list below
[^u]
u matches the character u with index 11710 (7516 or 1658) literally (case sensitive)
3rd Alternative
[^\\"]
Match a single character not present in the list below
[^\\"]
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
2nd Capturing Group
(\s*:)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
2nd Alternative
\b(true|false|null)\b
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
3rd Capturing Group
(true|false|null)
1st Alternative
true
true
matches the characters true literally (case sensitive)
2nd Alternative
false
false
matches the characters false literally (case sensitive)
3rd Alternative
null
null
matches the characters null literally (case sensitive)
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
3rd Alternative
-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?
-
matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:\.\d*)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:[eE][+\-]?\d+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[eE]
eE
matches a single character in the list eE (case sensitive)
Match a single character present in the list below
[+\-]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
+ matches the character + with index 4310 (2B16 or 538) literally (case sensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
4th Alternative
([\{\}\[\]])
4th Capturing Group
([\{\}\[\]])
Match a single character present in the list below
[\{\}\[\]]
\{ 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 9110 (5B16 or 1338) literally (case sensitive)
\] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
g

Test String