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+)\.(\w+) as \3(\d_\d)_)(, \2\.\w+ as \w+)*
/
g
1st Capturing Group
((\w+)\.(\w+) as \3(\d_\d)_)
2nd 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)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
3rd 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)
as
matches the characters as literally (case sensitive)
\3 matches the same text as most recently matched by the 3rd capturing group
4th Capturing Group
(\d_\d)
\d matches a digit (equivalent to [0-9])
_ matches the character _ with index 9510 (5F16 or 1378) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
_ matches the character _ with index 9510 (5F16 or 1378) literally (case sensitive)
5th Capturing Group
(, \2\.\w+ as \w+)*
* 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
,
matches the characters , literally (case sensitive)
\2 matches the same text as most recently matched by the 2nd capturing group
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\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)
as
matches the characters as literally (case sensitive)
\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)
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

/
/
g

Test String

Substitution

Processing...