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
"
^((grek\. afs\.)|(\S{2,6}\.))
"
gm
^ asserts position at start of a line
1st Capturing Group
((grek\. afs\.)|(\S{2,6}\.))
1st Alternative
(grek\. afs\.)
2nd Capturing Group
(grek\. afs\.)
grek
matches the characters grek literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
afs
matches the characters afs literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
2nd Alternative
(\S{2,6}\.)
3rd Capturing Group
(\S{2,6}\.)
\S
matches any non-whitespace character (equivalent to [^\r\n\t\f\v ])
{2,6} matches the previous token between 2 and 6 times, as many times as possible, giving back as needed (greedy)
\. matches the character . with index 4610 (2E16 or 568) 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.

Regular Expression
No Match

r"
"
gm

Test String