Regular Expressions 101

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

Save & Share

Flavor

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

Function

  • Match
  • Substitution
  • List
  • Unit Tests
@
(?(DEFINE) (?<next_open_tag> [^<] (?i: <[^<?s][^<] | <(?! \?php | \?= | script\slanguage\s=\s([\'"])php\g{-1}\s> ) [^<] )*+ (?i: <(?: \?php | \?= | [^>] ) | \z ) ) ) \A (?&next_open_tag) \K | [^'"`/#<?] (?: '(?:[^'\\]|\\.)*+' [^\'"`/#<?] | "(?:[^"\\]|\\.)*+" [^\'"`/#<?] | `(?:[^`\\]|\\.)*+` [^\'"`/#<?] | /(?![/*]) [^\'"`/#<?] # stop for // or /* | # if close tag ?> \? (?: >(?&next_open_tag)[^\'"`/#<?] | ) | < (?: # heredoc or nowdoc <<[\ \t]([\'"]) ([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]) \g{-2}[\ \t][\r\n] (?-s:.[\r\n])*? \g{-1}[\r\n;] [^\'"`/#<?] | (?i: /script\s>) (?&next_open_tag) [^\'"`/#<?] | [^\'"`/#<?] ) )*+ \K (?: (?://|\#)(?:[^\n?]|\?(?!>))*+ # single line comment // и # | /\*(?:[^*]|\*(?!/))*+\*/ # multi line comment /* */ )?
@
xsg
1st Alternative
(?(DEFINE) (?<next_open_tag> [^<] (?i: <[^<?s][^<] | <(?! \?php | \?= | script\slanguage\s=\s([\'"])php\g{-1}\s> ) [^<] )*+ (?i: <(?: \?php | \?= | [^>] ) | \z ) ) ) \A (?&next_open_tag) \K
Subpattern definition construct
(?(DEFINE) (?<next_open_tag> [^<] (?i: <[^<?s][^<] | <(?! \?php | \?= | script\slanguage\s=\s([\'"])php\g{-1}\s> ) [^<] )*+ (?i: <(?: \?php | \?= | [^>] ) | \z ) ) )
May only be used to define functions. No matching is done in this group.
Named Capture Group next_open_tag
(?<next_open_tag> [^<] (?i: <[^<?s][^<] | <(?! \?php | \?= | script\slanguage\s=\s([\'"])php\g{-1}\s> ) [^<] )*+ (?i: <(?: \?php | \?= | [^>] ) | \z ) )
Match a single character not present in the list below
[^<]
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
< matches the character < literally (case sensitive)
Non-capturing Group. Matches the tokens contained with the following effective flags: xsgi
(?i: <[^<?s][^<] | <(?! \?php | \?= | script\slanguage\s=\s([\'"])php\g{-1}\s> ) [^<] )*+
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
1st Alternative
<[^<?s][^<]
2nd Alternative
<(?! \?php | \?= | script\slanguage\s=\s([\'"])php\g{-1}\s> ) [^<]
Non-capturing Group. Matches the tokens contained with the following effective flags: xsgi
(?i: <(?: \?php | \?= | [^>] ) | \z )
\A asserts position at start of the string
(?&next_open_tag) recurses the subpattern named next_open_tag
\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match
2nd Alternative
[^'"`/#<?] (?: '(?:[^'\\]|\\.)*+' [^\'"`/#<?] | "(?:[^"\\]|\\.)*+" [^\'"`/#<?] | `(?:[^`\\]|\\.)*+` [^\'"`/#<?] | /(?![/*]) [^\'"`/#<?] # stop for // or /* | # if close tag ?> \? (?: >(?&next_open_tag)[^\'"`/#<?] | ) | < (?: # heredoc or nowdoc <<[\ \t]([\'"]) ([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]) \g{-2}[\ \t][\r\n] (?-s:.[\r\n])*? \g{-1}[\r\n;] [^\'"`/#<?] | (?i: /script\s>) (?&next_open_tag) [^\'"`/#<?] | [^\'"`/#<?] ) )*+ \K (?: (?://|\#)(?:[^\n?]|\?(?!>))*+ # single line comment // и # | /\*(?:[^*]|\*(?!/))*+\*/ # multi line comment /* */ )?
Match a single character not present in the list below
[^'"`/#<?]
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
'"`/#<? matches a single character in the list '"`/#<? (case sensitive)
Non-capturing group
(?: '(?:[^'\\]|\\.)*+' [^\'"`/#<?] | "(?:[^"\\]|\\.)*+" [^\'"`/#<?] | `(?:[^`\\]|\\.)*+` [^\'"`/#<?] | /(?![/*]) [^\'"`/#<?] # stop for // or /* | # if close tag ?> \? (?: >(?&next_open_tag)[^\'"`/#<?] | ) | < (?: # heredoc or nowdoc <<[\ \t]([\'"]) ([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]) \g{-2}[\ \t][\r\n] (?-s:.[\r\n])*? \g{-1}[\r\n;] [^\'"`/#<?] | (?i: /script\s>) (?&next_open_tag) [^\'"`/#<?] | [^\'"`/#<?] ) )*+
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
1st Alternative
'(?:[^'\\]|\\.)*+' [^\'"`/#<?]
' matches the character ' literally (case sensitive)
Non-capturing group
(?:[^'\\]|\\.)*+
*+ matches the previous token between zero and unlimited times, as many times as possible, without giving back (possessive)
1st Alternative
[^'\\]
2nd Alternative
\\.
' matches the character ' literally (case sensitive)
Match a single character not present in the list below
[^\'"`/#<?]
2nd Alternative
"(?:[^"\\]|\\.)*+" [^\'"`/#<?]
" matches the character " literally (case sensitive)
Non-capturing group
(?:[^"\\]|\\.)*+
" matches the character " literally (case sensitive)
Match a single character not present in the list below
[^\'"`/#<?]
3rd Alternative
`(?:[^`\\]|\\.)*+` [^\'"`/#<?]
` matches the character ` literally (case sensitive)
Non-capturing group
(?:[^`\\]|\\.)*+
` matches the character ` literally (case sensitive)
Match a single character not present in the list below
[^\'"`/#<?]
4th Alternative
/(?![/*]) [^\'"`/#<?] # stop for // or /*
5th Alternative
# if close tag ?> \? (?: >(?&next_open_tag)[^\'"`/#<?] | )
6th Alternative
< (?: # heredoc or nowdoc <<[\ \t]([\'"]) ([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]) \g{-2}[\ \t][\r\n] (?-s:.[\r\n])*? \g{-1}[\r\n;] [^\'"`/#<?] | (?i: /script\s>) (?&next_open_tag) [^\'"`/#<?] | [^\'"`/#<?] )
\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match
Non-capturing group
(?: (?://|\#)(?:[^\n?]|\?(?!>))*+ # single line comment // и # | /\*(?:[^*]|\*(?!/))*+\*/ # multi line comment /* */ )?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
(?://|\#)(?:[^\n?]|\?(?!>))*+ # single line comment // и #
2nd Alternative
/\*(?:[^*]|\*(?!/))*+\*/ # multi line comment /* */
Global pattern flags
x modifier: extended. Spaces and text after a # in the pattern are ignored
s modifier: single line. Dot matches newline characters
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

@
@
xsg

Test String

Substitution

Processing...