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
/
\?((?:(?<rid>regionId)=(?<ridv>[\d\$,_]+)|(?<sid>sectionId)=(?<sidv>(?P>ridv))|(?<a>age)=(?<av>(?P>ridv))|(?<p>purpose)=(?<pv>(?P>ridv))|(?<l>lineId)=(?<lv>(?P>ridv))|(?<stid>stationId)=(?<stidv>(?P>ridv))|(?<pe>price)=(?<pev>(?P>ridv)))&?)+
/
m
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
1st Capturing Group
((?:(?<rid>regionId)=(?<ridv>[\d\$,_]+)|(?<sid>sectionId)=(?<sidv>(?P>ridv))|(?<a>age)=(?<av>(?P>ridv))|(?<p>purpose)=(?<pv>(?P>ridv))|(?<l>lineId)=(?<lv>(?P>ridv))|(?<stid>stationId)=(?<stidv>(?P>ridv))|(?<pe>price)=(?<pev>(?P>ridv)))&?)+
+ matches the previous token between one 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
Non-capturing group
(?:(?<rid>regionId)=(?<ridv>[\d\$,_]+)|(?<sid>sectionId)=(?<sidv>(?P>ridv))|(?<a>age)=(?<av>(?P>ridv))|(?<p>purpose)=(?<pv>(?P>ridv))|(?<l>lineId)=(?<lv>(?P>ridv))|(?<stid>stationId)=(?<stidv>(?P>ridv))|(?<pe>price)=(?<pev>(?P>ridv)))
1st Alternative
(?<rid>regionId)=(?<ridv>[\d\$,_]+)
Named Capture Group rid
(?<rid>regionId)
regionId
matches the characters regionId literally (case sensitive)
= matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
Named Capture Group ridv
(?<ridv>[\d\$,_]+)
Match a single character present in the list below
[\d\$,_]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\d matches a digit (equivalent to [0-9])
\$ matches the character $ with index 3610 (2416 or 448) literally (case sensitive)
,_
matches a single character in the list ,_ (case sensitive)
2nd Alternative
(?<sid>sectionId)=(?<sidv>(?P>ridv))
Named Capture Group sid
(?<sid>sectionId)
sectionId
matches the characters sectionId literally (case sensitive)
= matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
Named Capture Group sidv
(?<sidv>(?P>ridv))
(?P>ridv) recurses the subpattern named ridv
3rd Alternative
(?<a>age)=(?<av>(?P>ridv))
Named Capture Group a
(?<a>age)
age
matches the characters age literally (case sensitive)
= matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
Named Capture Group av
(?<av>(?P>ridv))
(?P>ridv) recurses the subpattern named ridv
4th Alternative
(?<p>purpose)=(?<pv>(?P>ridv))
Named Capture Group p
(?<p>purpose)
purpose
matches the characters purpose literally (case sensitive)
= matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
Named Capture Group pv
(?<pv>(?P>ridv))
(?P>ridv) recurses the subpattern named ridv
5th Alternative
(?<l>lineId)=(?<lv>(?P>ridv))
Named Capture Group l
(?<l>lineId)
lineId
matches the characters lineId literally (case sensitive)
= matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
Named Capture Group lv
(?<lv>(?P>ridv))
(?P>ridv) recurses the subpattern named ridv
6th Alternative
(?<stid>stationId)=(?<stidv>(?P>ridv))
Named Capture Group stid
(?<stid>stationId)
stationId
matches the characters stationId literally (case sensitive)
= matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
Named Capture Group stidv
(?<stidv>(?P>ridv))
(?P>ridv) recurses the subpattern named ridv
7th Alternative
(?<pe>price)=(?<pev>(?P>ridv))
Named Capture Group pe
(?<pe>price)
price
matches the characters price literally (case sensitive)
= matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
Named Capture Group pev
(?<pev>(?P>ridv))
(?P>ridv) recurses the subpattern named ridv
&
matches the character & with index 3810 (2616 or 468) literally (case sensitive)
Global pattern flags
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

/
/
m

Test String