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
/
(?:$|^|)(red-|blue-|indigo-|cool-gray-|pink-|yellow-|teal-|gray-|orange-|green-|purple-)(50|100|200|300|400|500|600|700|800|900)(?:$|^|)
/
gi
Non-capturing group
(?:$|^|)
1st Alternative
$
$ asserts position at the end of the string
2nd Alternative
^
^ asserts position at start of the string
3rd Alternative null, matches any position
1st Capturing Group
(red-|blue-|indigo-|cool-gray-|pink-|yellow-|teal-|gray-|orange-|green-|purple-)
1st Alternative
red-
red-
matches the characters red- literally (case insensitive)
2nd Alternative
blue-
blue-
matches the characters blue- literally (case insensitive)
3rd Alternative
indigo-
indigo-
matches the characters indigo- literally (case insensitive)
4th Alternative
cool-gray-
cool-gray-
matches the characters cool-gray- literally (case insensitive)
5th Alternative
pink-
pink-
matches the characters pink- literally (case insensitive)
6th Alternative
yellow-
yellow-
matches the characters yellow- literally (case insensitive)
7th Alternative
teal-
teal-
matches the characters teal- literally (case insensitive)
8th Alternative
gray-
gray-
matches the characters gray- literally (case insensitive)
9th Alternative
orange-
orange-
matches the characters orange- literally (case insensitive)
10th Alternative
green-
green-
matches the characters green- literally (case insensitive)
11th Alternative
purple-
2nd Capturing Group
(50|100|200|300|400|500|600|700|800|900)
1st Alternative
50
50
matches the characters 50 literally (case insensitive)
2nd Alternative
100
100
matches the characters 100 literally (case insensitive)
3rd Alternative
200
200
matches the characters 200 literally (case insensitive)
4th Alternative
300
300
matches the characters 300 literally (case insensitive)
5th Alternative
400
400
matches the characters 400 literally (case insensitive)
6th Alternative
500
500
matches the characters 500 literally (case insensitive)
7th Alternative
600
600
matches the characters 600 literally (case insensitive)
8th Alternative
700
700
matches the characters 700 literally (case insensitive)
9th Alternative
800
800
matches the characters 800 literally (case insensitive)
10th Alternative
900
Non-capturing group
(?:$|^|)
1st Alternative
$
$ asserts position at the end of the string
2nd Alternative
^
^ asserts position at start of the string
3rd Alternative null, matches any position
Global pattern flags
g modifier: global. All matches (don't return after first match)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
gi

Test String