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
/
.*?(?={\/?[_\w]*}|$){\/a}
/
.
matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Positive Lookahead
(?={\/?[_\w]*}|$)
Assert that the Regex below matches
1st Alternative
{\/?[_\w]*}
{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
\/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
? 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
[_\w]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
_ matches the character _ with index 9510 (5F16 or 1378) literally (case sensitive)
\w matches any word character (equivalent to [a-zA-Z0-9_])
} matches the character } with index 12510 (7D16 or 1758) literally (case sensitive)
2nd Alternative
$
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
{ matches the character { with index 12310 (7B16 or 1738) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
a}
matches the characters a} literally (case sensitive)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/

Test String