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
/
(?:{if\s+)(.*?)(?:})((?:(?R)|(.*?))*)(?:{endif})
/
s
Non-capturing group
(?:{if\s+)
{if
matches the characters {if literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
1st Capturing Group
(.*?)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Non-capturing group
(?:})
} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
2nd Capturing Group
((?:(?R)|(.*?))*)
Non-capturing group
(?:(?R)|(.*?))*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
1st Alternative
(?R)
(?R) recurses the entire pattern
2nd Alternative
(.*?)
3rd Capturing Group
(.*?)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Non-capturing group
(?:{endif})
{endif}
matches the characters {endif} literally (case sensitive)
Global pattern flags
s modifier: single line. Dot matches newline characters
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
s

Test String