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+)(([A-Z][A-Za-z\'\-]+)\.?\s+)*([A-Z][A-Z\'\-]*\.?)(\s+[A-Z][A-Z\'\-]*\.?)*,?(\s+([A-z][A-z\'\-]+))*(\s*\([^\(\)]*\))?:(\s*\([^\(\)]*\))*
/
gm
1st Capturing Group
(^|[.\?\!]\s+)
1st Alternative
^
^ asserts position at start of a line
2nd Alternative
[.\?\!]\s+
Match a single character present in the list below
[.\?\!]
. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
\! matches the character ! with index 3310 (2116 or 418) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
2nd Capturing Group
(([A-Z][A-Za-z\'\-]+)\.?\s+)*
* 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
3rd Capturing Group
([A-Z][A-Za-z\'\-]+)
Match a single character present in the list below
[A-Z]
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
Match a single character present in the list below
[A-Za-z\'\-]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
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 the character ' with index 3910 (2716 or 478) literally (case sensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
\.
matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
? 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 one and unlimited times, as many times as possible, giving back as needed (greedy)
4th Capturing Group
([A-Z][A-Z\'\-]*\.?)
Match a single character present in the list below
[A-Z]
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
Match a single character present in the list below
[A-Z\'\-]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
\' matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
\.
matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
5th Capturing Group
(\s+[A-Z][A-Z\'\-]*\.?)*
* 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
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[A-Z]
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
Match a single character present in the list below
[A-Z\'\-]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
\' matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
\.
matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
,
matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
6th Capturing Group
(\s+([A-z][A-z\'\-]+))*
* 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
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
7th Capturing Group
([A-z][A-z\'\-]+)
Match a single character present in the list below
[A-z]
A-z matches a single character in the range between A (index 65) and z (index 122) (case sensitive)
Match a single character present in the list below
[A-z\'\-]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
A-z matches a single character in the range between A (index 65) and z (index 122) (case sensitive)
\' matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
8th 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 4010 (2816 or 508) 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 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 the character : with index 5810 (3A16 or 728) literally (case sensitive)
9th Capturing Group
(\s*\([^\(\)]*\))*
* 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
\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 4010 (2816 or 508) 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 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)
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