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*define\s*\(\s*[\'"](\w*?)[\'"]\s*)(,\s*([\'"].*?[\'"]|.*?)\s*)((?:,\s*(?:true|false)\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*define\s*\(\s*[\'"](\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)
define
matches the characters define literally (case insensitive)
\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 4010 (2816 or 508) literally (case insensitive)
\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)
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)
3rd Capturing Group
(\w*?)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
*? 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)
\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)
4th Capturing Group
(,\s*([\'"].*?[\'"]|.*?)\s*)
, matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
\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)
6th Capturing Group
((?:,\s*(?:true|false)\s*)?\)\s*;)
Non-capturing group
(?:,\s*(?:true|false)\s*)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
, matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
\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)
Non-capturing group
(?:true|false)
1st Alternative
true
true
matches the characters true literally (case insensitive)
2nd Alternative
false
false
matches the characters false literally (case insensitive)
\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 4110 (2916 or 518) literally (case insensitive)
\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

Code Generator

Generated Code

Loading code sample...
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report.
For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm