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
"
((?<=จังหวัด\s)|(?<=จังหวัด)|(?<=\.\s)|(?<=\.)|(?<=\s))([-]+)|(กรุงเทพ[มหานคร]*)|(กทม)
"
gm
1st Alternative
((?<=จังหวัด\s)|(?<=จังหวัด)|(?<=\.\s)|(?<=\.)|(?<=\s))([-]+)
1st Capturing Group
((?<=จังหวัด\s)|(?<=จังหวัด)|(?<=\.\s)|(?<=\.)|(?<=\s))
1st Alternative
(?<=จังหวัด\s)
Positive Lookbehind
(?<=จังหวัด\s)
Assert that the Regex below matches
จังหวัด
matches the characters จังหวัด literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
2nd Alternative
(?<=จังหวัด)
Positive Lookbehind
(?<=จังหวัด)
Assert that the Regex below matches
จังหวัด
matches the characters จังหวัด literally (case sensitive)
3rd Alternative
(?<=\.\s)
Positive Lookbehind
(?<=\.\s)
Assert that the Regex below matches
matches the character with index 359210 (E0816 or 70108) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
4th Alternative
(?<=\.)
Positive Lookbehind
(?<=\.)
Assert that the Regex below matches
matches the character with index 359210 (E0816 or 70108) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
5th Alternative
(?<=\s)
Positive Lookbehind
(?<=\s)
Assert that the Regex below matches
matches the character with index 359210 (E0816 or 70108) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
2nd Capturing Group
([-]+)
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 range between (index 3585) and (index 3673) (case sensitive)
2nd Alternative
(กรุงเทพ[มหานคร]*)
3rd Capturing Group
(กรุงเทพ[มหานคร]*)
กรุงเทพ
matches the characters กรุงเทพ literally (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)
3rd Alternative
(กทม)
4th Capturing Group
(กทม)
กทม
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.

Regular Expression
No Match

r"
"
gm

Test String