Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
"
^\s*<p>\s*(?:</?\w+/?>\s*)*<a href=\"(?:(?:[a-z]+:)?//(?:[^\" >/.]*\.)*(?:youtube\.com|youtu\.be)[/\"])\W*(?![\W\w]*?</(?:code|blockquote)>)(?#Separate start with youtube watch; lower TP rate, but most TP are not otherwise detected)
"
gm
^ asserts position at start of a line
\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)
<p>
matches the characters <p> 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)
Non-capturing group
(?:</?\w+/?>\s*)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
< matches the character < with index 6010 (3C16 or 748) literally (case sensitive)
/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
> matches the character > with index 6210 (3E16 or 768) 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)
<a href=
matches the characters <a href= literally (case sensitive)
\" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
Non-capturing group
(?:(?:[a-z]+:)?//(?:[^\" >/.]*\.)*(?:youtube\.com|youtu\.be)[/\"])
Non-capturing group
(?:[a-z]+:)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[a-z]
+ matches the previous token between one 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)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
//
matches the characters // literally (case sensitive)
Non-capturing group
(?:[^\" >/.]*\.)*
* 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
[^\" >/.]
* matches the previous token between zero 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 a single character in the list >/. (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
Non-capturing group
(?:youtube\.com|youtu\.be)
1st Alternative
youtube\.com
youtube
matches the characters youtube literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
com
matches the characters com literally (case sensitive)
2nd Alternative
youtu\.be
youtu
matches the characters youtu literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
be
matches the characters be literally (case sensitive)
Match a single character present in the list below
[/\"]
/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
\W
matches any non-word character (equivalent to [^a-zA-Z0-9_])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?![\W\w]*?</(?:code|blockquote)>)
Assert that the Regex below does not match
Match a single character present in the list below
[\W\w]
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\W matches any non-word character (equivalent to [^a-zA-Z0-9_])
\w matches any word character (equivalent to [a-zA-Z0-9_])
</
matches the characters </ literally (case sensitive)
Non-capturing group
(?:code|blockquote)
1st Alternative
code
code
matches the characters code literally (case sensitive)
2nd Alternative
blockquote
blockquote
matches the characters blockquote literally (case sensitive)
> matches the character > with index 6210 (3E16 or 768) literally (case sensitive)
Comment: Separate start with youtube watch; lower TP rate, but most TP are not otherwise detected
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)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
gm

Test String

Code Generator

Generated Code

Loading code sample...
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report.
For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html