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
/
^(rgb\s*?\(\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?\))$|^(rgba\s*?\(\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(0|0\.\d*|1|1.0*)\s*?\))$|^(transparent)$|^(#([a-fA-F0-9]){3})$|^(#([a-fA-F0-9]){6}$)|(^hsl\s*?\(\s*?(000|0?\d{1,2}|[1-2]\d\d|3[0-5]\d|360)\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?\)$)|(^hsla\s*?\(\s*?(000|0?\d{1,2}|[1-2]\d\d|3[0-5]\d|360)\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?,\s*?(0|0\.\d*|1|1.0*)\s*?\)$)$
/
1st Alternative
^(rgb\s*?\(\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?\))$
^ asserts position at start of the string
1st Capturing Group
(rgb\s*?\(\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?\))
rgb
matches the characters rgb literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
2nd Capturing Group
(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])
1st Alternative
000
000
matches the characters 000 literally (case sensitive)
2nd Alternative
0?\d{1,2}
0
matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{1,2} matches the previous token between 1 and 2 times, as many times as possible, giving back as needed (greedy)
3rd Alternative
1\d\d
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
4th Alternative
2[0-4]\d
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[0-4]
0-4 matches a single character in the range between 0 (index 48) and 4 (index 52) (case sensitive)
\d matches a digit (equivalent to [0-9])
5th Alternative
25[0-5]
25
matches the characters 25 literally (case sensitive)
Match a single character present in the list below
[0-5]
0-5 matches a single character in the range between 0 (index 48) and 5 (index 53) (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
3rd Capturing Group
(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])
1st Alternative
000
000
matches the characters 000 literally (case sensitive)
2nd Alternative
0?\d{1,2}
0
matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{1,2} matches the previous token between 1 and 2 times, as many times as possible, giving back as needed (greedy)
3rd Alternative
1\d\d
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
4th Alternative
2[0-4]\d
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[0-4]
0-4 matches a single character in the range between 0 (index 48) and 4 (index 52) (case sensitive)
\d matches a digit (equivalent to [0-9])
5th Alternative
25[0-5]
25
matches the characters 25 literally (case sensitive)
Match a single character present in the list below
[0-5]
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
4th Capturing Group
(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])
1st Alternative
000
000
matches the characters 000 literally (case sensitive)
2nd Alternative
0?\d{1,2}
0
matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
3rd Alternative
1\d\d
4th Alternative
2[0-4]\d
5th Alternative
25[0-5]
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
$ asserts position at the end of the string
2nd Alternative
^(rgba\s*?\(\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(0|0\.\d*|1|1.0*)\s*?\))$
^ asserts position at start of the string
5th Capturing Group
(rgba\s*?\(\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\s*?,\s*?(0|0\.\d*|1|1.0*)\s*?\))
rgba
matches the characters rgba literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
6th Capturing Group
(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])
1st Alternative
000
000
matches the characters 000 literally (case sensitive)
2nd Alternative
0?\d{1,2}
0
matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{1,2} matches the previous token between 1 and 2 times, as many times as possible, giving back as needed (greedy)
3rd Alternative
1\d\d
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
4th Alternative
2[0-4]\d
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[0-4]
0-4 matches a single character in the range between 0 (index 48) and 4 (index 52) (case sensitive)
\d matches a digit (equivalent to [0-9])
5th Alternative
25[0-5]
25
matches the characters 25 literally (case sensitive)
Match a single character present in the list below
[0-5]
0-5 matches a single character in the range between 0 (index 48) and 5 (index 53) (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
7th Capturing Group
(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])
1st Alternative
000
000
matches the characters 000 literally (case sensitive)
2nd Alternative
0?\d{1,2}
0
matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{1,2} matches the previous token between 1 and 2 times, as many times as possible, giving back as needed (greedy)
3rd Alternative
1\d\d
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
4th Alternative
2[0-4]\d
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[0-4]
0-4 matches a single character in the range between 0 (index 48) and 4 (index 52) (case sensitive)
\d matches a digit (equivalent to [0-9])
5th Alternative
25[0-5]
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
8th Capturing Group
(000|0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])
1st Alternative
000
000
matches the characters 000 literally (case sensitive)
2nd Alternative
0?\d{1,2}
3rd Alternative
1\d\d
4th Alternative
2[0-4]\d
5th Alternative
25[0-5]
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
9th Capturing Group
(0|0\.\d*|1|1.0*)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
$ asserts position at the end of the string
3rd Alternative
^(transparent)$
^ asserts position at start of the string
10th Capturing Group
(transparent)
transparent
matches the characters transparent literally (case sensitive)
$ asserts position at the end of the string
4th Alternative
^(#([a-fA-F0-9]){3})$
^ asserts position at start of the string
11th Capturing Group
(#([a-fA-F0-9]){3})
# matches the character # with index 3510 (2316 or 438) literally (case sensitive)
12th Capturing Group
([a-fA-F0-9]){3}
{3} matches the previous token exactly 3 times
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
Match a single character present in the list below
[a-fA-F0-9]
a-f matches a single character in the range between a (index 97) and f (index 102) (case sensitive)
A-F matches a single character in the range between A (index 65) and F (index 70) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
$ asserts position at the end of the string
5th Alternative
^(#([a-fA-F0-9]){6}$)
^ asserts position at start of the string
13th Capturing Group
(#([a-fA-F0-9]){6}$)
# matches the character # with index 3510 (2316 or 438) literally (case sensitive)
14th Capturing Group
([a-fA-F0-9]){6}
{6} matches the previous token exactly 6 times
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
Match a single character present in the list below
[a-fA-F0-9]
a-f matches a single character in the range between a (index 97) and f (index 102) (case sensitive)
A-F matches a single character in the range between A (index 65) and F (index 70) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
$ asserts position at the end of the string
6th Alternative
(^hsl\s*?\(\s*?(000|0?\d{1,2}|[1-2]\d\d|3[0-5]\d|360)\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?\)$)
15th Capturing Group
(^hsl\s*?\(\s*?(000|0?\d{1,2}|[1-2]\d\d|3[0-5]\d|360)\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?\)$)
^ asserts position at start of the string
hsl
matches the characters hsl literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
16th Capturing Group
(000|0?\d{1,2}|[1-2]\d\d|3[0-5]\d|360)
1st Alternative
000
000
matches the characters 000 literally (case sensitive)
2nd Alternative
0?\d{1,2}
0
matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{1,2} matches the previous token between 1 and 2 times, as many times as possible, giving back as needed (greedy)
3rd Alternative
[1-2]\d\d
Match a single character present in the list below
[1-2]
1-2 matches a single character in the range between 1 (index 49) and 2 (index 50) (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
4th Alternative
3[0-5]\d
5th Alternative
360
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
17th Capturing Group
(000|100|0?\d{2}|0?0?\d)
% matches the character % with index 3710 (2516 or 458) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
18th Capturing Group
(000|100|0?\d{2}|0?0?\d)
% matches the character % with index 3710 (2516 or 458) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
$ asserts position at the end of the string
7th Alternative
(^hsla\s*?\(\s*?(000|0?\d{1,2}|[1-2]\d\d|3[0-5]\d|360)\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?,\s*?(0|0\.\d*|1|1.0*)\s*?\)$)$
19th Capturing Group
(^hsla\s*?\(\s*?(000|0?\d{1,2}|[1-2]\d\d|3[0-5]\d|360)\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?,\s*?(000|100|0?\d{2}|0?0?\d)%\s*?,\s*?(0|0\.\d*|1|1.0*)\s*?\)$)
^ asserts position at start of the string
hsla
matches the characters hsla literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
20th Capturing Group
(000|0?\d{1,2}|[1-2]\d\d|3[0-5]\d|360)
1st Alternative
000
000
matches the characters 000 literally (case sensitive)
2nd Alternative
0?\d{1,2}
0
matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
3rd Alternative
[1-2]\d\d
4th Alternative
3[0-5]\d
5th Alternative
360
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
21st Capturing Group
(000|100|0?\d{2}|0?0?\d)
% matches the character % with index 3710 (2516 or 458) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
22nd Capturing Group
(000|100|0?\d{2}|0?0?\d)
% matches the character % with index 3710 (2516 or 458) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
23rd Capturing Group
(0|0\.\d*|1|1.0*)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
$ asserts position at the end of the string
$ asserts position at the end of the string
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/

Test String