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
/
(?<name>\D*?) (?<grade>(A)?(B)?(C)?(D)?(E)?(FX)?(F)?)(?<ex>(-+)|(\++))?
/
gm
Named Capture Group name
(?<name>\D*?)
\D
matches any character that's not a digit (equivalent to [^0-9])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
Named Capture Group grade
(?<grade>(A)?(B)?(C)?(D)?(E)?(FX)?(F)?)
3rd Capturing Group
(A)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
A matches the character A with index 6510 (4116 or 1018) literally (case sensitive)
4th Capturing Group
(B)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
B matches the character B with index 6610 (4216 or 1028) literally (case sensitive)
5th Capturing Group
(C)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
C matches the character C with index 6710 (4316 or 1038) literally (case sensitive)
6th Capturing Group
(D)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
D matches the character D with index 6810 (4416 or 1048) literally (case sensitive)
7th Capturing Group
(E)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
E matches the character E with index 6910 (4516 or 1058) literally (case sensitive)
8th Capturing Group
(FX)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
FX
matches the characters FX literally (case sensitive)
9th Capturing Group
(F)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
F matches the character F with index 7010 (4616 or 1068) literally (case sensitive)
Named Capture Group ex
(?<ex>(-+)|(\++))?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
(-+)
11th Capturing Group
(-+)
-
matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
2nd Alternative
(\++)
12th Capturing Group
(\++)
\+
matches the character + with index 4310 (2B16 or 538) literally (case sensitive)
+ 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)
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.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gm

Test String