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
/
(^去机场$)|接送(|服务)|()?(|服务)
/
gm
1st Alternative
(^去机场$)
1st Capturing Group
(^去机场$)
^ asserts position at start of a line
去机场
matches the characters 去机场 literally (case sensitive)
$ asserts position at the end of a line
2nd Alternative
接送(|服务)
接送
matches the characters 接送 literally (case sensitive)
2nd Capturing Group
(|服务)
1st Alternative
matches the character with index 2642610 (673A16 or 634728) literally (case sensitive)
2nd Alternative
服务
服务
matches the characters 服务 literally (case sensitive)
3rd Alternative
()?(|服务)
matches the character with index 3686510 (900116 or 1100018) literally (case sensitive)
3rd Capturing Group
()?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
matches the character with index 2104010 (523016 or 510608) literally (case sensitive)
matches the character with index 2642610 (673A16 or 634728) literally (case sensitive)
4th Capturing Group
(|服务)
1st Alternative
matches the character with index 2233010 (573A16 or 534728) literally (case sensitive)
2nd Alternative
服务
服务
matches the characters 服务 literally (case sensitive)
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