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
"
([A-Z0-9-]+)\.txt:NAME:\s\"module\s\w+\s([0-9/]+)\",\sDESCR:\s\"(.+)\"
"
g
1st Capturing Group
([A-Z0-9-]+)
Match a single character present in the list below
[A-Z0-9-]
+ 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 65) and Z (index 90) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
txt:NAME:
matches the characters txt:NAME: literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
\" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
module
matches the characters module literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
\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)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
2nd Capturing Group
([0-9/]+)
Match a single character present in the list below
[0-9/]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
DESCR:
matches the characters DESCR: literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
\" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
3rd 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)
\" matches the character " with index 3410 (2216 or 428) 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