Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
"
^(([NEW]|S[WS]*N)*S[WS]*E([ES]|W[WS]*E)*W[WS]*N)*([NEW]|S[WS]*N)*S[WS]*E([ES]|W[WS]*E)*N[NEWS]*$
"
^ asserts position at start of the string
1st Capturing Group
(([NEW]|S[WS]*N)*S[WS]*E([ES]|W[WS]*E)*W[WS]*N)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
2nd Capturing Group
([NEW]|S[WS]*N)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
1st Alternative
[NEW]
Match a single character present in the list below
[NEW]
NEW
matches a single character in the list NEW (case sensitive)
2nd Alternative
S[WS]*N
S matches the character S with index 8310 (5316 or 1238) literally (case sensitive)
Match a single character present in the list below
[WS]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
WS
matches a single character in the list WS (case sensitive)
N matches the character N with index 7810 (4E16 or 1168) literally (case sensitive)
S matches the character S with index 8310 (5316 or 1238) literally (case sensitive)
Match a single character present in the list below
[WS]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
WS
matches a single character in the list WS (case sensitive)
E matches the character E with index 6910 (4516 or 1058) literally (case sensitive)
3rd Capturing Group
([ES]|W[WS]*E)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
1st Alternative
[ES]
Match a single character present in the list below
[ES]
ES
matches a single character in the list ES (case sensitive)
2nd Alternative
W[WS]*E
W matches the character W with index 8710 (5716 or 1278) literally (case sensitive)
Match a single character present in the list below
[WS]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
WS
matches a single character in the list WS (case sensitive)
E matches the character E with index 6910 (4516 or 1058) literally (case sensitive)
W matches the character W with index 8710 (5716 or 1278) literally (case sensitive)
Match a single character present in the list below
[WS]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
WS
matches a single character in the list WS (case sensitive)
N matches the character N with index 7810 (4E16 or 1168) literally (case sensitive)
4th Capturing Group
([NEW]|S[WS]*N)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
1st Alternative
[NEW]
Match a single character present in the list below
[NEW]
NEW
matches a single character in the list NEW (case sensitive)
2nd Alternative
S[WS]*N
S matches the character S with index 8310 (5316 or 1238) literally (case sensitive)
Match a single character present in the list below
[WS]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
WS
matches a single character in the list WS (case sensitive)
N matches the character N with index 7810 (4E16 or 1168) literally (case sensitive)
S matches the character S with index 8310 (5316 or 1238) literally (case sensitive)
Match a single character present in the list below
[WS]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
WS
matches a single character in the list WS (case sensitive)
E matches the character E with index 6910 (4516 or 1058) literally (case sensitive)
5th Capturing Group
([ES]|W[WS]*E)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
1st Alternative
[ES]
Match a single character present in the list below
[ES]
ES
matches a single character in the list ES (case sensitive)
2nd Alternative
W[WS]*E
W matches the character W with index 8710 (5716 or 1278) literally (case sensitive)
Match a single character present in the list below
[WS]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
WS
matches a single character in the list WS (case sensitive)
E matches the character E with index 6910 (4516 or 1058) literally (case sensitive)
N matches the character N with index 7810 (4E16 or 1168) literally (case sensitive)
Match a single character present in the list below
[NEWS]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
NEWS
matches a single character in the list NEWS (case sensitive)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"

Test String