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
/
\d{1,3}\.\s[a-zA-Z\d\?\.\s].+$\n\s(a?\)\s[a-zA-Z].+).+\n\s(b?\)\s[A-Za-z].+).+\n\s(c\).[a-zA-Z].+)
/
gm
\d
matches a digit (equivalent to [0-9])
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
Match a single character present in the list below
[a-zA-Z\d\?\.\s]
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)
\d matches a digit (equivalent to [0-9])
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
$ asserts position at the end of a line
\n matches a line-feed (newline) character (ASCII 10)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
1st Capturing Group
(a?\)\s[a-zA-Z].+)
a
matches the character a with index 9710 (6116 or 1418) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
Match a single character present in the list below
[a-zA-Z]
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)
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
2nd Capturing Group
(b?\)\s[A-Za-z].+)
b
matches the character b with index 9810 (6216 or 1428) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
Match a single character present in the list below
[A-Za-z]
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
3rd Capturing Group
(c\).[a-zA-Z].+)
c matches the character c with index 9910 (6316 or 1438) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
. matches any character (except for line terminators)
Match a single character present in the list below
[a-zA-Z]
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)
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
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