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 (4)
`
(?:semlps/401k-retirement-services|semlps/aca|semlps/avs|semlps/flsa|semlps/guides|semlps/InsHB|semlps/insurance|semlps/is-national|semlps/sbsdemandgen|semlps/simple-ira|semlps/talent-management|semlps/workers-comp)(?:/)?(?:.*[^0-9a-zA-Z].*)?(?:\\.aspx)?$
`
gm
Non-capturing group
(?:semlps/401k-retirement-services|semlps/aca|semlps/avs|semlps/flsa|semlps/guides|semlps/InsHB|semlps/insurance|semlps/is-national|semlps/sbsdemandgen|semlps/simple-ira|semlps/talent-management|semlps/workers-comp)
1st Alternative
semlps/401k-retirement-services
semlps/401k-retirement-services
matches the characters semlps/401k-retirement-services literally (case sensitive)
2nd Alternative
semlps/aca
semlps/aca
matches the characters semlps/aca literally (case sensitive)
3rd Alternative
semlps/avs
semlps/avs
matches the characters semlps/avs literally (case sensitive)
4th Alternative
semlps/flsa
semlps/flsa
matches the characters semlps/flsa literally (case sensitive)
5th Alternative
semlps/guides
semlps/guides
matches the characters semlps/guides literally (case sensitive)
6th Alternative
semlps/InsHB
semlps/InsHB
matches the characters semlps/InsHB literally (case sensitive)
7th Alternative
semlps/insurance
semlps/insurance
matches the characters semlps/insurance literally (case sensitive)
8th Alternative
semlps/is-national
semlps/is-national
matches the characters semlps/is-national literally (case sensitive)
9th Alternative
semlps/sbsdemandgen
semlps/sbsdemandgen
matches the characters semlps/sbsdemandgen literally (case sensitive)
10th Alternative
semlps/simple-ira
semlps/simple-ira
matches the characters semlps/simple-ira literally (case sensitive)
11th Alternative
semlps/talent-management
semlps/talent-management
matches the characters semlps/talent-management literally (case sensitive)
12th Alternative
semlps/workers-comp
Non-capturing group
(?:/)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
Non-capturing group
(?:.*[^0-9a-zA-Z].*)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character not present in the list below
[^0-9a-zA-Z]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:\\.aspx)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
. matches any character (except for line terminators)
aspx
matches the characters aspx literally (case sensitive)
$ asserts position at the end of a line
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)

Regular Expression

`
`
gm

Unit Tests

given the string https://apple.com/semlps/401k-retirement… assert that regex does match
given the string https://wifi.com/semlps/401k-retirement-… assert that regex does not match
given the string https://letstryiat.com/semlps/avs/electr… assert that regex does match
given the string https://letstryiat.com/semlps/avs/electr… assert that regex does not match