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
"
\W\b(A[CLPM]|BA|CE|DF|GO|ES|M[ATSG]|P[ABREI]|R[JNSOR]|S[PCE]|TO)\W
"
g
\W matches any non-word character (equivalent to [^a-zA-Z0-9_])
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
1st Capturing Group
(A[CLPM]|BA|CE|DF|GO|ES|M[ATSG]|P[ABREI]|R[JNSOR]|S[PCE]|TO)
1st Alternative
A[CLPM]
A matches the character A with index 6510 (4116 or 1018) literally (case sensitive)
Match a single character present in the list below
[CLPM]
CLPM
matches a single character in the list CLPM (case sensitive)
2nd Alternative
BA
BA
matches the characters BA literally (case sensitive)
3rd Alternative
CE
CE
matches the characters CE literally (case sensitive)
4th Alternative
DF
DF
matches the characters DF literally (case sensitive)
5th Alternative
GO
GO
matches the characters GO literally (case sensitive)
6th Alternative
ES
ES
matches the characters ES literally (case sensitive)
7th Alternative
M[ATSG]
M matches the character M with index 7710 (4D16 or 1158) literally (case sensitive)
Match a single character present in the list below
[ATSG]
ATSG
matches a single character in the list ATSG (case sensitive)
8th Alternative
P[ABREI]
P matches the character P with index 8010 (5016 or 1208) literally (case sensitive)
Match a single character present in the list below
[ABREI]
ABREI
matches a single character in the list ABREI (case sensitive)
9th Alternative
R[JNSOR]
R matches the character R with index 8210 (5216 or 1228) literally (case sensitive)
Match a single character present in the list below
[JNSOR]
JNSOR
matches a single character in the list JNSOR (case sensitive)
10th Alternative
S[PCE]
S matches the character S with index 8310 (5316 or 1238) literally (case sensitive)
Match a single character present in the list below
[PCE]
PCE
matches a single character in the list PCE (case sensitive)
11th Alternative
TO
TO
matches the characters TO literally (case sensitive)
\W matches any non-word character (equivalent to [^a-zA-Z0-9_])
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
g

Test String