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
"
(?P<gclid>(?<=gclid=).*?(?=&|\\s|$))
"
gm
Named Capture Group gclid
(?P<gclid>(?<=gclid=).*?(?=&|\\s|$))
Positive Lookbehind
(?<=gclid=)
Assert that the Regex below matches
gclid=
matches the characters gclid= literally (case sensitive)
.
matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Positive Lookahead
(?=&|\\s|$)
Assert that the Regex below matches
1st Alternative
&
& matches the character & with index 3810 (2616 or 468) literally (case sensitive)
2nd Alternative
\\s
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
s matches the character s with index 11510 (7316 or 1638) literally (case sensitive)
3rd Alternative
$
$ asserts position at the end of a line
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.

Regular Expression
No Match

r"
"
gm

Test String