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
/
(background:\s*url\((https?:\/\/)*([a-zA-Z0-9._:\/\s*]*)\)\s*[a-zA-Z0-9\s*-._:\/;]*)
/
g
1st Capturing Group
(background:\s*url\((https?:\/\/)*([a-zA-Z0-9._:\/\s*]*)\)\s*[a-zA-Z0-9\s*-._:\/;]*)
background:
matches the characters background: literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
url
matches the characters url literally (case sensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
2nd Capturing Group
(https?:\/\/)*
* 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
http
matches the characters http literally (case sensitive)
s
matches the character s with index 11510 (7316 or 1638) literally (case sensitive)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
3rd Capturing Group
([a-zA-Z0-9._:\/\s*]*)
Match a single character present in the list below
[a-zA-Z0-9._:\/\s*]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
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)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
._:
matches a single character in the list ._: (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the character * with index 4210 (2A16 or 528) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[a-zA-Z0-9\s*-._:\/;]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
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)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
*-. matches a single character in the range between * (index 42) and . (index 46) (case sensitive)
_:
matches a single character in the list _: (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
; matches the character ; with index 5910 (3B16 or 738) literally (case sensitive)
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
g

Test String

Regex Debugger

Please wait while your expression is being debugged...