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
/
(?<=\/\/:)[\r\n]*(.*?)(?=[\r\n]*\/\/\~[\r\n]*\*)
/
sg
Positive Lookbehind
(?<=\/\/:)
Assert that the Regex below matches
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
Match a single character present in the list below
[\r\n]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\r matches a carriage return (ASCII 13)
\n matches a line-feed (newline) character (ASCII 10)
1st Capturing Group
(.*?)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Positive Lookahead
(?=[\r\n]*\/\/\~[\r\n]*\*)
Assert that the Regex below matches
Match a single character present in the list below
[\r\n]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\r matches a carriage return (ASCII 13)
\n matches a line-feed (newline) character (ASCII 10)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\~ matches the character ~ with index 12610 (7E16 or 1768) literally (case sensitive)
Match a single character present in the list below
[\r\n]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\r matches a carriage return (ASCII 13)
\n matches a line-feed (newline) character (ASCII 10)
\* matches the character * with index 4210 (2A16 or 528) literally (case sensitive)
Global pattern flags
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

/
/
sg

Test String