Regular Expressions 101

@regex101
Donate
Sponsor
Contact
Bug Reports & Feedback
Wiki
Whats new?

Save & Share

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

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python 2.7
  • Golang (RE2)

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
<\s*(\w+\b)(?:(?!<\s*\/\s*\1\b)[\s\S])*<\s*\/\s*\1\s*>|\S+
/
g
1st Alternative
<\s*(\w+\b)(?:(?!<\s*\/\s*\1\b)[\s\S])*<\s*\/\s*\1\s*>
< matches the character < literally (case sensitive)
\s*
matches any whitespace character (equal to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
1st Capturing Group
(\w+\b)
\w+
matches any word character (equal to [a-zA-Z0-9_])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
\b assert position at a word boundary: (^\\w|\\w$|\\W\\w|\\w\\W)
Non-capturing group
(?:(?!<\s*\/\s*\1\b)[\s\S])*
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?!<\s*\/\s*\1\b)
Assert that the Regex below does not match
< matches the character < literally (case sensitive)
\s*
matches any whitespace character (equal to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\/ matches the character / literally (case sensitive)
\s*
matches any whitespace character (equal to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\1 matches the same text as most recently matched by the 1st capturing group
\b assert position at a word boundary: (^\\w|\\w$|\\W\\w|\\w\\W)
Match a single character present in the list below
[\s\S]
\s matches any whitespace character (equal to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\S matches any non-whitespace character (equal to [^\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
< matches the character < literally (case sensitive)
\s*
matches any whitespace character (equal to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\/ matches the character / literally (case sensitive)
\s*
matches any whitespace character (equal to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\1 matches the same text as most recently matched by the 1st capturing group
\s*
matches any whitespace character (equal to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
> matches the character > literally (case sensitive)
2nd Alternative
\S+
\S+
matches any non-whitespace character (equal to [^\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
g

Test String