Regular Expressions 101

Save & Share

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

Flavor

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

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
(?<=^|;|<\?php\s|<\?\s)(\s*?)(\h*\$(\w+)\s*=)(\s*([\'"].*?[\'"]|.*?)\s*;)
/
imsg
Positive Lookbehind
(?<=^|;|<\?php\s|<\?\s)
Assert that the Regex below matches
1st Alternative
^
^ asserts position at start of a line
2nd Alternative
;
; matches the character ; with index 5910 (3B16 or 738) literally (case insensitive)
3rd Alternative
<\?php\s
< matches the character < with index 6010 (3C16 or 748) literally (case insensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case insensitive)
php
matches the characters php literally (case insensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
4th Alternative
<\?\s
< matches the character < with index 6010 (3C16 or 748) literally (case insensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case insensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
1st Capturing Group
(\s*?)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
2nd Capturing Group
(\h*\$(\w+)\s*=)
\h
matches any horizontal whitespace character (equivalent to [[:blank:]])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\$ matches the character $ with index 3610 (2416 or 448) literally (case insensitive)
3rd Capturing Group
(\w+)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
= matches the character = with index 6110 (3D16 or 758) literally (case insensitive)
4th Capturing Group
(\s*([\'"].*?[\'"]|.*?)\s*;)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
5th Capturing Group
([\'"].*?[\'"]|.*?)
1st Alternative
[\'"].*?[\'"]
Match a single character present in the list below
[\'"]
\' matches the character ' with index 3910 (2716 or 478) literally (case insensitive)
" matches the character " with index 3410 (2216 or 428) literally (case insensitive)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Match a single character present in the list below
[\'"]
\' matches the character ' with index 3910 (2716 or 478) literally (case insensitive)
" matches the character " with index 3410 (2216 or 428) literally (case insensitive)
2nd Alternative
.*?
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
; matches the character ; with index 5910 (3B16 or 738) literally (case insensitive)
Global pattern flags
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
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

/
/
imsg

Test String

Regex Debugger

Please wait while your expression is being debugged...