Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(?mx)(?# PCRE 8.x )" & @CRLF & _ "" & @CRLF & _ "^" & @CRLF & _ "(?<scheme> (?i) [a-z0-9+.-]+ (?-i) )" & @CRLF & _ ":" & @CRLF & _ "(?:\/\/" & @CRLF & _ "(?<authority>" & @CRLF & _ "(?<userinfo> (?<username> (?&uriUnreserved)+ ) (?: : (?<password> (?&uriUnreserved)+ )? )? @ )?" & @CRLF & _ "(?<host>" & @CRLF & _ "| (?'ipv4' (?&_ipv4) )" & @CRLF & _ "| \[ (?'ipv6' (?&_ipv6) ) \]" & @CRLF & _ "| (?<hostname> (?i) (?: (?&hostLabel) \. )* (?&hostLabel) (?-i) )" & @CRLF & _ ")" & @CRLF & _ "(?: : (?<port> (?&port_number) ) )?" & @CRLF & _ ")" & @CRLF & _ ")?" & @CRLF & _ "(?# If an authority component is present, then the path component must either be empty or begin with a slash. If an authority component is absent, then the path cannot begin with an empty segment, that is with two slashes as the following characters would be interpreted as an authority component. )" & @CRLF & _ "(?# TODO: Exception: file URI scheme RFC 8089 https://en.wikipedia.org/wiki/File_URI_scheme )" & @CRLF & _ "(?<path> (?(authority) (?= [\/?#] | $ ) | (?! \/\/ ) ) (?&pathSequence) )" & @CRLF & _ "(?: \? (?'query'(?&_query)) )?" & @CRLF & _ "(?: \# (?<fragment>(?&_fragment)))?" & @CRLF & _ "$" & @CRLF & _ "" & @CRLF & _ "(?(DEFINE)" & @CRLF & _ "" & @CRLF & _ "(?# http://es5.github.io/#A.6 )" & @CRLF & _ "(?<uriCharacter> (?&uriReserved) | (?&uriUnescaped) | (?&uriEscaped) )" & @CRLF & _ "(?<uriReserved> [;\/?:@&=+$,] )" & @CRLF & _ "(?<uriUnescaped> [[:alpha:]\d] | (?&uriMark) )" & @CRLF & _ "(?<uriEscaped> %[[:xdigit]]{2} )" & @CRLF & _ "(?<uriMark> [-_.!~*`()] )" & @CRLF & _ "(?<uriUnreserved> (?&uriUnescaped) | (?&uriEscaped) )" & @CRLF & _ "" & @CRLF & _ "(?# https://en.wikipedia.org/wiki/Uniform_Resource_Identifier )" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "(?# allowed characters per RFC 952, RFC 1123 )" & @CRLF & _ "(?<hostLabel> [a-z0-9-]{1,63} )" & @CRLF & _ "" & @CRLF & _ "(?<_ipv4> (?: (?&octet) \. ){3} (?&octet) )" & @CRLF & _ "(?<octet> (?&_250_255) | (?&_200_249) | (?&_0_199) )" & @CRLF & _ "(?<_250_255> 25[0-5] )" & @CRLF & _ "(?<_200_249> 2[0-4]\d )" & @CRLF & _ "(?<_0_199> 1? (?&_0_99) )" & @CRLF & _ "(?<_0_99> [1-9]? \d )" & @CRLF & _ "" & @CRLF & _ "(?<_ipv6> (?&ipv6_2) )" & @CRLF & _ "(?<ipv6_1> (?&hextet) :: (?: (?&hextet) : ){0,5} (?&hextet) )" & @CRLF & _ "(?<ipv6_2> (?&hextet) : (?&hextet) :: (?: (?&hextet) : ){0,4} (?&hextet) )" & @CRLF & _ "(?<ipv6_3> (?: (?&hextet) : ){2} :: (?: ) )" & @CRLF & _ "(?<ipv6_4> )" & @CRLF & _ "(?<ipv6_5> )" & @CRLF & _ "(?<ipv6_6> )" & @CRLF & _ "(?<ipv6_7> )" & @CRLF & _ "(?<ipv6_8> )" & @CRLF & _ "(?<hextet> [[:xdigit:]]{1,4} )" & @CRLF & _ "" & @CRLF & _ "(?<port_number> (?&_65530_65535) | (?&_65500_65529) | (?&_65000_65499) | (?&_60000_64999) | (?&_10000_59999) | (?&_1000_9999) | (?&_100_999) | (?&_0_99) )" & @CRLF & _ "(?<_65530_65535> 6553[0-5] )" & @CRLF & _ "(?<_65500_65529> 655[0-2]\d )" & @CRLF & _ "(?<_65000_65499> 65[0-4]\d{2} )" & @CRLF & _ "(?<_60000_64999> 6[0-4]\d{3} )" & @CRLF & _ "(?<_10000_59999> [1-5]\d{4} )" & @CRLF & _ "(?<_1000_9999> [1-9]\d{3} )" & @CRLF & _ "(?<_100_999> [1-9]\d{2} )" & @CRLF & _ "" & @CRLF & _ "(?<pathSequence> (?: (?&pathSegment) \/ )* (?&pathSegment)? )" & @CRLF & _ "(?<pathSegment> (?: (?&uriUnreserved) | [:@!$&'()*+,;=] )* )" & @CRLF & _ "#(?<pathSegment> (?: (?&uriUnreserved) | [:@] )* )" & @CRLF & _ "" & @CRLF & _ "(?<_query> (?: (?&uriUnreserved) | [:@!$&'()*+,;=?\/] )* )" & @CRLF & _ "(?<_fragment> (?: (?&uriUnreserved) | [:@!$&'()*+,;=?\/] )* )" & @CRLF & _ "" & @CRLF & _ ")" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" Local $sString = "https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top" & @CRLF & _ "ldap://[2001:db8::7]/c=GB?objectClass?one" & @CRLF & _ "http://myuser:inadvisiblepassword@this.test.com:80/dir/filename.xml?var1=foo&var2=bar#zap" & @CRLF & _ "mailto:John.Doe@example.com" & @CRLF & _ "news:comp.infosystems.www.servers.unix" & @CRLF & _ "tel:+1-816-555-1212" & @CRLF & _ "telnet://192.0.2.16:80/" & @CRLF & _ "urn:oasis:names:specification:docbook:dtd:xml:4.1.2" & @CRLF & _ "" Local $sSubst = "{\n\tscheme: "${scheme}",\n\tauthority: {\n\t\tuserinfo: {\n\t\t\tusername: "${username}",\n\t\t\tpassword: "${password}"\n\t\t},\n\t\thost: {\n\t\t\thostname: "\L${hostname}\E",\n\t\t\tipv4: "${ipv4}",\n\t\t\tipv6: "\L${ipv6}\E"\n\t\t},\n\t\tport: "${port}"\n\t},\n\tpath: "${path}",\n\tquery: "${query}",\n\tfragment: "${fragment}"\n}\n\n" 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