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
"
闹钟|.{0,3}[|早|醒|我|起]+
"
gm
1st Alternative
闹钟
闹钟
matches the characters 闹钟 literally (case sensitive)
2nd Alternative
.{0,3}[|早|醒|我|起]+
matches the character with index 2148310 (53EB16 or 517538) literally (case sensitive)
.
matches any character (except for line terminators)
{0,3} matches the previous token between 0 and 3 times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[|早|醒|我|起]
+ matches the previous token between one 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

Code Generator

Generated Code

Loading code sample...
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report.
For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html