Regular Expressions 101

Save & Share

  • Regex Version: ver. 5
  • 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
No Match

r"
"
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)(?:^(\w{1,255}):(.{1,255})@|^)(?:(?:(?=\S{0,253}(?:$|:| ))((?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+(?:[a-z0-9]{1,63})))|localhost)(:\d{1,5})?" Local $sString = "Valid localhost addresses:" & @CRLF & _ "localhost" & @CRLF & _ "user:password@localhost:80" & @CRLF & _ "localhost:8080/path/to/page.html" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Valid IPv4 addresses:" & @CRLF & _ "10.10.0.1 " & @CRLF & _ "192.168.0.1 " & @CRLF & _ "192.168.0.1:8888 " & @CRLF & _ "user:password@192.168.0.1:8888 " & @CRLF & _ "user:password@192.168.0.1" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Valid IPv6 addresses: // regex does not check for that, check here: http://vernon.mauery.com/content/projects/linux/ipv6_regex" & @CRLF & _ "" & @CRLF & _ "100::" & @CRLF & _ "100::ffff:ffff:ffff:ffff" & @CRLF & _ "::ffff:0.0.0.0" & @CRLF & _ "64:ff9b::0.0.0.0" & @CRLF & _ "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" & @CRLF & _ "fe80::" & @CRLF & _ "2001:2f:ffff:ffff:ffff:ffff:ffff:ffff" & @CRLF & _ "2001:db8::" & @CRLF & _ "::1" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Valid domains: // all should work" & @CRLF & _ "www.test.com" & @CRLF & _ "www1.test.com" & @CRLF & _ "www1.test.com:8080 " & @CRLF & _ "test.com" & @CRLF & _ "test-test.com" & @CRLF & _ "test.com/path/to/page?var=1&var2=2" & @CRLF & _ "test.com:80" & @CRLF & _ "user:password@test.com" & @CRLF & _ "user:password@test-test.com" & @CRLF & _ "user:password@test.com/path/to/page" & @CRLF & _ "user:password@test.com/path/to/page?var=1&var2=2" & @CRLF & _ "user:password@test.com:80" & @CRLF & _ "user:password@test.com:80/path/to/page?var=1&var2=2" & @CRLF & _ "Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.com" & @CRLF & _ "user:password@Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.com" & @CRLF & _ "user:password@Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.com:8080" & @CRLF & _ "Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.MaximumLengthOf63CharactersForATopLevelDomainWithoutTheDashes" & @CRLF & _ "Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.MaximumLengthOf63CharactersForATopLevelDomainWithoutTheDashes:8888" & @CRLF & _ "user:password@Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.Maximum-Length-Of-63-Characters-For-A-Subdomain-Completely-Used.MaximumLengthOf63CharactersForATopLevelDomainWithoutTheDashes:8888" & @CRLF & _ "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a // Maximum number of 127 suddomains, seperated by 126 dots" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "Invalid domains: // should not work" & @CRLF & _ "justLongGibberishBLABLABLA " & @CRLF & _ "againButThisTimeWithNumbers12345675678797 " & @CRLF & _ "ShouldNOTWorkBecauseOfTheDash-.com" & @CRLF & _ "UrlLenghtIsValidButThisSubdomainIsTooLongMaximumForASubdomainIs63Characters.com " & @CRLF & _ "This-Url-Has-Valid-Subdomains.But-The-Url-Length-In-General-Is-Too-Long.This-Means-Longer-Than-253-Characters-For-The-Complete-Url.Including-The-Top-Level-Domain-Itself.So-This-Line-Shouldnt-Be-Catched-By-The-Regex.Its-Exactly-One-Character-Too-Long1.com" 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