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-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?)(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?)|([a-zA-Z ]+))(\s+)?$
/
gm
^ asserts position at start of a line
1st 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 \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
2nd Capturing Group
(((([a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?)(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?)|([a-zA-Z ]+))
1st Alternative
((([a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?)(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?)
3rd Capturing Group
((([a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?)(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?)
4th Capturing Group
(([a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?)
5th Capturing Group
([a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)
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)
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 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 the character - with index 4510 (2D16 or 558) literally (case sensitive)
\– matches the character with index 821110 (201316 or 200238) literally (case sensitive)
\` matches the character ` with index 9610 (6016 or 1408) literally (case sensitive)
\' matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
\’ matches the character with index 821710 (201916 or 200318) literally (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 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)
6th Capturing Group
(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
7th Capturing Group
((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+))
1st Alternative
(\s+[a-zA-Z]+)
8th Capturing Group
(\s+[a-zA-Z]+)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
+ 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-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 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)
2nd Alternative
(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)
9th Capturing Group
(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
+ 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-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)
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 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 the character - with index 4510 (2D16 or 558) literally (case sensitive)
\– matches the character with index 821110 (201316 or 200238) literally (case sensitive)
\` matches the character ` with index 9610 (6016 or 1408) literally (case sensitive)
\' matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
\’ matches the character with index 821710 (201916 or 200318) literally (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 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)
10th Capturing Group
(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
11th Capturing Group
((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+))
1st Alternative
(\s+[a-zA-Z]+)
12th Capturing Group
(\s+[a-zA-Z]+)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
+ 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-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 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)
2nd Alternative
(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)
13th Capturing Group
(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
+ 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-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)
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 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 the character - with index 4510 (2D16 or 558) literally (case sensitive)
\– matches the character with index 821110 (201316 or 200238) literally (case sensitive)
\` matches the character ` with index 9610 (6016 or 1408) literally (case sensitive)
\' matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
\’ matches the character with index 821710 (201916 or 200318) literally (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 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)
14th Capturing Group
(((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)))?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
15th Capturing Group
((\s+[a-zA-Z]+)|(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+))
1st Alternative
(\s+[a-zA-Z]+)
16th Capturing Group
(\s+[a-zA-Z]+)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
+ 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-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 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)
2nd Alternative
(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)
17th Capturing Group
(\s+[a-zA-Z][a-zA-Z\-\–\`\'\’]+[a-zA-Z]+)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
+ 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-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)
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 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 the character - with index 4510 (2D16 or 558) literally (case sensitive)
\– matches the character with index 821110 (201316 or 200238) literally (case sensitive)
\` matches the character ` with index 9610 (6016 or 1408) literally (case sensitive)
\' matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
\’ matches the character with index 821710 (201916 or 200318) literally (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 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)
2nd Alternative
([a-zA-Z ]+)
18th Capturing Group
([a-zA-Z ]+)
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 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 the character with index 3210 (2016 or 408) literally (case sensitive)
19th 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 \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
+ 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
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.

Regular Expression
No Match

/
/
gm

Test String