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
Match a single character present in the list below
[明天|几点钟|时候]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
明天|几点钟|时候
matches a single character in the list 明天|几点钟时候 (case sensitive)
Match a single character present in the list below
[退房]
退房
matches a single character in the list 退房 (case sensitive)
Match a single character present in the list below
[的时间|几点钟|?]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
的时间|几点钟|?
matches a single character in the list 的时间|几点钟? (case sensitive)
Match a single character present in the list below
[吗|啊|呢]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
吗|啊|呢
matches a single character in the list 吗|啊呢 (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.

Regular Expression
No Match

r"
"
gm

Test String