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
/
url(\((['\" ])*(?!data:|https?:\/\/)([^\"'\)]+)['\" ]*)
/
g
url
matches the characters url literally (case sensitive)
1st Capturing Group
(\((['\" ])*(?!data:|https?:\/\/)([^\"'\)]+)['\" ]*)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
2nd Capturing Group
(['\" ])*
* 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
Match a single character present in the list below
['\" ]
' matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
\" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
Negative Lookahead
(?!data:|https?:\/\/)
Assert that the Regex below does not match
1st Alternative
data:
data:
matches the characters data: literally (case sensitive)
2nd Alternative
https?:\/\/
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
([^\"'\)]+)
Match a single character not present in the list below
[^\"'\)]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
' matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
Match a single character present in the list below
['\" ]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
' matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
\" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
matches the character with index 3210 (2016 or 408) 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