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
"
(\w+)(?:(?:@)|(?:\s+[Aa][Tt]\s+))(.+)(?:(?:\.edu)|(?:\s+[dD][oO][Tt]\s+edu))
"
g
1st Capturing Group
(\w+)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:(?:@)|(?:\s+[Aa][Tt]\s+))
1st Alternative
(?:@)
Non-capturing group
(?:@)
@ matches the character @ with index 6410 (4016 or 1008) literally (case sensitive)
2nd Alternative
(?:\s+[Aa][Tt]\s+)
Non-capturing group
(?:\s+[Aa][Tt]\s+)
\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
[Aa]
Aa
matches a single character in the list Aa (case sensitive)
Match a single character present in the list below
[Tt]
Tt
matches a single character in the list Tt (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
(.+)
.
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)
Non-capturing group
(?:(?:\.edu)|(?:\s+[dD][oO][Tt]\s+edu))
1st Alternative
(?:\.edu)
Non-capturing group
(?:\.edu)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
edu
matches the characters edu literally (case sensitive)
2nd Alternative
(?:\s+[dD][oO][Tt]\s+edu)
Non-capturing group
(?:\s+[dD][oO][Tt]\s+edu)
\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
[dD]
dD
matches a single character in the list dD (case sensitive)
Match a single character present in the list below
[oO]
oO
matches a single character in the list oO (case sensitive)
Match a single character present in the list below
[Tt]
Tt
matches a single character in the list Tt (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)
edu
matches the characters edu literally (case sensitive)
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
g

Test String