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
`
(?:\s|^|\(|\[)(#[0-9]+)(?:\s|$|\)|\]|\.|\,(?:\s|$))
`
smg
Non-capturing group
(?:\s|^|\(|\[)
1st Alternative
\s
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
2nd Alternative
^
^ asserts position at start of a line
3rd Alternative
\(
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
4th Alternative
\[
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
1st Capturing Group
(#[0-9]+)
# matches the character # with index 3510 (2316 or 438) literally (case sensitive)
Match a single character present in the list below
[0-9]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
Non-capturing group
(?:\s|$|\)|\]|\.|\,(?:\s|$))
1st Alternative
\s
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
2nd Alternative
$
$ asserts position at the end of a line
3rd Alternative
\)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
4th Alternative
\]
\] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
5th Alternative
\.
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
6th Alternative
\,(?:\s|$)
\, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
Non-capturing group
(?:\s|$)
1st Alternative
\s
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
2nd Alternative
$
$ asserts position at the end of a line
Global pattern flags
s modifier: single line. Dot matches newline characters
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

`
`
smg

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 Golang, please visit: https://golang.org/pkg/regexp/