Regular Expressions 101

Save & Share

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
No Match

/
/
gmi

Test String

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?mi)^([0-9]{8,10}[^a-zA-Z\s])$" Local $sString = "This is a number also 123-456-7890" & @CRLF & _ "This is not a number: 123456" & @CRLF & _ "This is not a number, but an address 123 456" & @CRLF & _ "My parameters are 90/60/90 - 120/150/120 - not a phone number" & @CRLF & _ "I am cheeky and I use letter 0 instead of zero 604_213_0293 Or I use | symbol" & @CRLF & _ "and also 604_2|3_0293 may happen" & @CRLF & _ "The most classical Canadian number is +1(604)123-4567 hi hi" & @CRLF & _ "Dashes can be different 123-456–7890" & @CRLF & _ "And looks like phone +I(800)-2l4-15O but contain combination with letter" & @CRLF & _ "" & @CRLF & _ " 'oi+I(222)3334444oi'," & @CRLF & _ " 'io+0 (222) 333 444Ooi'," & @CRLF & _ " 'O+l ( 222 ) 3|3 4O40O'," & @CRLF & _ " '+O+l ( 222 ) 3|3 4O40O'," & @CRLF & _ "069123521" & @CRLF & _ "0691235523" & @CRLF & _ "06912355312" & @CRLF & _ "in text 123-567" & @CRLF & _ "+(1)-23567 text" & @CRLF & _ "in text 123567-2 text" & @CRLF & _ "" & @CRLF & _ "---------------------------------------" & @CRLF & _ "" & @CRLF & _ "in text 1-800-123-123" & @CRLF & _ "1-800-123-123 text" & @CRLF & _ "in text 1-800-123-123 text" & @CRLF & _ "" & @CRLF & _ "---------------------------------------" & @CRLF & _ "" & @CRLF & _ "in text 1-800-123-123" & @CRLF & _ "1-800-123-123 text" & @CRLF & _ "in text 1-800-123-123 text" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "---------------------------------------" & @CRLF & _ "n0OOOOOOOOOOOO" & @CRLF & _ "" & @CRLF & _ "h1iiiiiiiiiiiii" & @CRLF & _ "" & @CRLF & _ "in text +l-800-123-123" & @CRLF & _ "1-8oo-I23-i23 text" & @CRLF & _ "in text +1 (800)-l23-123 text" & @CRLF & _ "" & @CRLF & _ "phone" & @CRLF & _ " '012345678'," & @CRLF & _ " '0123456789'," & @CRLF & _ " '01234567891'," & @CRLF & _ " '012345678912'," & @CRLF & _ " '0123456789123'," & @CRLF & _ " '01234567891234'," & @CRLF & _ " '012345678912345'," & @CRLF & _ " '800-1234567'," & @CRLF & _ " '8Oo-I234567-l'," & @CRLF & _ " '+1(222)3334444'," & @CRLF & _ " '+1 (222) 333 4444'," & @CRLF & _ " '+1 ( 222 ) 333 4444'," & @CRLF & _ " '+1-222-333-4444'," & @CRLF & _ " '+1 222 333 4444'," & @CRLF & _ " '236 - 332 - 6669'," & @CRLF & _ " '(604)123-4567'," & @CRLF & _ " '604 123 4567'," & @CRLF & _ " '604_123_4567'," & @CRLF & _ " '2368337551'," & @CRLF & _ " '12223334444'," & @CRLF & _ " '222) 333 4444'," & @CRLF & _ " '3333 4444'," & @CRLF & _ " '(437)1234567'," & @CRLF & _ " '(888)1234123'," & @CRLF & _ "" & @CRLF & _ "not a phone" & @CRLF & _ " '0'," & @CRLF & _ " '01'," & @CRLF & _ " '012'," & @CRLF & _ " '0123'," & @CRLF & _ " '01234'," & @CRLF & _ " '012345'," & @CRLF & _ " '0123456'," & @CRLF & _ " '01234567'," & @CRLF & _ " '90-60-90'," & @CRLF & _ " '90/60/90'," & @CRLF & _ " '0123456789123456'," & @CRLF & _ " '+X (XXX) XXX XXXX'," & @CRLF & _ " '1/23-4'," & @CRLF & _ " '1 / 23 - 4'," & @CRLF & _ " '1234/12,3-1234'" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "Result")

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