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
"
\b[\+\w\.-]+@((?!gmail|yahoo|hotmail|gmx|mail|outlook).)[\w\.-]+\.\w{2,7}\b
"
gmi
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
Match a single character present in the list below
[\+\w\.-]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\+ matches the character + with index 4310 (2B16 or 538) literally (case insensitive)
\w matches any word character (equivalent to [a-zA-Z0-9_])
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
@ matches the character @ with index 6410 (4016 or 1008) literally (case insensitive)
1st Capturing Group
((?!gmail|yahoo|hotmail|gmx|mail|outlook).)
Negative Lookahead
(?!gmail|yahoo|hotmail|gmx|mail|outlook)
Assert that the Regex below does not match
1st Alternative
gmail
gmail
matches the characters gmail literally (case insensitive)
2nd Alternative
yahoo
yahoo
matches the characters yahoo literally (case insensitive)
3rd Alternative
hotmail
hotmail
matches the characters hotmail literally (case insensitive)
4th Alternative
gmx
gmx
matches the characters gmx literally (case insensitive)
5th Alternative
mail
mail
matches the characters mail literally (case insensitive)
6th Alternative
outlook
outlook
matches the characters outlook literally (case insensitive)
. matches any character (except for line terminators)
Match a single character present in the list below
[\w\.-]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\w matches any word character (equivalent to [a-zA-Z0-9_])
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
{2,7} matches the previous token between 2 and 7 times, as many times as possible, giving back as needed (greedy)
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
matches the character with index 1010 (A16 or 128) literally (case insensitive)
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)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
gmi

Test String