Regular Expressions 101

Save & Share

  • Regex Version: ver. 10
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(?m)<ref\s+((?:group|follow|extends)\s*=(?:(?!name\s*=)[\s\S])*)?name\s*=\s*(?:"\s*([^"](?:(?!\s*\/>|\s*"\s*>|\s+(?:group|follow|extends)).)*?)\s*"|'\s*([^'"](?:(?!\s*\/>|\s*'>|\s+(?:group|follow|extends)).)*?)\s*'|([^"](?:(?!\s*\/>|\s*>|\s+(?:group|follow|extends)).)*))(\s+(?:group|follow|extends)\s*=(?:(?!\s*\/>|"\s*>|'\s*>)[\s\S])*)*\s*(?:(\/)|)>" Local $sString = "<ref name=Test1 /><ref name=Test2 />" & @CRLF & _ "<ref name=Bad 1 /><ref name=Bad 2 />" & @CRLF & _ "<ref name="Test 3"/>" & @CRLF & _ "<ref name="Test 4" />" & @CRLF & _ "<ref name=Test5>Foo</ref>" & @CRLF & _ "<ref name="Test 6">Foo</ref>" & @CRLF & _ "<ref " & @CRLF & _ " name=Test7>Foo" & @CRLF & _ "</ref>" & @CRLF & _ "<ref " & @CRLF & _ " name = Test8 >" & @CRLF & _ " Foo" & @CRLF & _ "</ref> " & @CRLF & _ "<ref name = Test9 > Foo </ref>" & @CRLF & _ "<ref " & @CRLF & _ " name="Test 10">Foo" & @CRLF & _ "</ref>" & @CRLF & _ "<ref " & @CRLF & _ " name = "Test 11" >" & @CRLF & _ " Foo" & @CRLF & _ "</ref>" & @CRLF & _ "<ref name = Test12 > Foo </ref>" & @CRLF & _ "<ref name = Test13 />" & @CRLF & _ "<ref name = "Test 14" />" & @CRLF & _ "<ref " & @CRLF & _ " name = Test15 />" & @CRLF & _ "<ref" & @CRLF & _ " name =" & @CRLF & _ " "Test 16"" & @CRLF & _ "/>" & @CRLF & _ "<ref" & @CRLF & _ " name" & @CRLF & _ " =" & @CRLF & _ " Test17" & @CRLF & _ " />" & @CRLF & _ "<ref" & @CRLF & _ " name" & @CRLF & _ " =" & @CRLF & _ " "Test 18"" & @CRLF & _ " />" & @CRLF & _ "<ref name="Test/19" />" & @CRLF & _ "==A heading==" & @CRLF & _ "<ref name = "Test/20" />" & @CRLF & _ "<ref name = "Test 21"/>" & @CRLF & _ "<ref name = "Test / 22"/>" & @CRLF & _ "<ref name = "Test > 23"/>" & @CRLF & _ "<ref name="Te>st/ 23.1"/>" & @CRLF & _ "<ref" & @CRLF & _ " name" & @CRLF & _ " ="" & @CRLF & _ " Test 24" & @CRLF & _ " "/>" & @CRLF & _ "<ref name='Test/ 25' />" & @CRLF & _ "<ref name='Test/ 26'> Foo </ref>" & @CRLF & _ "<ref name='Te>st/ 27' />" & @CRLF & _ "<ref name = " Test 28 " >Foo</ref>" & @CRLF & _ "<ref name='Test "29"' /> - This one is expected to produce invalid XML "'Test "29"'"; surprisingly, MW can parse it anyway for a case this simple, but not if there's a space within the interior-most quotes: "'Test "2 9"'"" & @CRLF & _ "<ref name = "Test 30" >" & @CRLF & _ "<ref name = "Test 31">" & @CRLF & _ "<ref name = "Test 32" />" & @CRLF & _ "<ref name = "Test 33"/>" & @CRLF & _ "<ref name = Test34 >" & @CRLF & _ "<ref name = Test35>" & @CRLF & _ "<ref name = Test36 />" & @CRLF & _ "<ref name = Test37/>" & @CRLF & _ "<ref name = " Test 38 "/>" & @CRLF & _ "<ref name = " Test 39 " />" & @CRLF & _ "<ref name='Test 40'/>" & @CRLF & _ "<ref name=AAA/>" & @CRLF & _ "<ref name="BBB AAA BBB" />" & @CRLF & _ "<ref name="This "isjustnot" valid"/> - This one is expected to produce invalid XML "This "isjustnot" valid"; surprisingly, MW can parse it anyway for a case this simple, but not if there's a space within the interior-most quotes: "This "is just not" valid"." & @CRLF & _ "<ref name="This 'actually is' valid"/>" & @CRLF & _ "<ref name='But this "is also" a problem' /> (or will be after our " substitution)" & @CRLF & _ "<ref name=apostrophe's />" & @CRLF & _ "<ref name="more apostrophe's" />" & @CRLF & _ "<ref name='this's bad, but we can fix it!' />" & @CRLF & _ "<ref name='this is okay'/>" & @CRLF & _ "<ref name="'this is dumb'"/>" & @CRLF & _ "<ref name="this is 'less' dumb" />" & @CRLF & _ "<ref name="what about 'this case'"/>" & @CRLF & _ "<ref name="'or this' one" />" & @CRLF & _ "" & @CRLF & _ "<ref name="foo" group="bar"/>" & @CRLF & _ "<ref name="foo" group="bar" />" & @CRLF & _ "<ref group="bar" name="foo" />" & @CRLF & _ "<ref name='foo' group='bar'/>" & @CRLF & _ "<ref name='foo' group='bar' />" & @CRLF & _ "<ref group='bar' name='foo' />" & @CRLF & _ "<ref name=foo group=bar/>" & @CRLF & _ "<ref name=foo group=bar />" & @CRLF & _ "<ref group=bar name=foo/>" & @CRLF & _ "<ref name="foo" follow="bar" />" & @CRLF & _ "<ref name='foo' follow='bar'/>" & @CRLF & _ "<ref name=foo follow=bar/>" & @CRLF & _ "<ref name="foo" extends="bar" />" & @CRLF & _ "<ref name='foo' extends='bar'/>" & @CRLF & _ "<ref name=foo extends=bar/>" & @CRLF & _ "<ref name='foo' group="bar" extends=baz follow="quux quux" />" & @CRLF & _ "<ref group="bar" name='foo' extends=baz follow="quux quux" />" & @CRLF & _ "<ref group="bar" extends=baz name='foo' follow="quux quux" />" & @CRLF & _ "<ref group="bar" extends=baz follow="quux quux" name='foo' />" & @CRLF & _ "<ref group="bar" extends=baz name=foo follow="quux quux" />" & @CRLF & _ "<ref group="bar" extends=baz name="foo's foo" follow="quux quux" />" & @CRLF & _ "<ref group="bar's > / bar" extends=baz name='foos > / foo' follow="quux quux" />" & @CRLF & _ "<ref group=" & @CRLF & _ " "bar's > / bar"" & @CRLF & _ " extends=" & @CRLF & _ " baz" & @CRLF & _ " name=" & @CRLF & _ " '" & @CRLF & _ " foos > / foo" & @CRLF & _ " '" & @CRLF & _ " follow=" & @CRLF & _ " "quux > quux"" & @CRLF & _ " />" & @CRLF & _ "<ref name="foos > / foo" group="bar's > / bar" extends=baz follow="quux quux"/>" & @CRLF & _ "<ref " & @CRLF & _ " name = " & @CRLF & _ " '" & @CRLF & _ " foos > / foo" & @CRLF & _ " '" & @CRLF & _ " group = " & @CRLF & _ " "bar's > / bar"" & @CRLF & _ " extends" & @CRLF & _ " =baz" & @CRLF & _ " follow" & @CRLF & _ " ="" & @CRLF & _ " quux quux" & @CRLF & _ " "" & @CRLF & _ " />" & @CRLF & _ "<ref name="foos > / foo" group="bar's > / bar" extends=baz follow='quux quux'/>" & @CRLF & _ "" Local $sSubst = "<ref $1name="$2$3$4"$5${6:+ /:}>" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult)

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