Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?m)(?i)(?<scheme>http|https|ftp|sftp|sip|sips|file):\/\/(?:(?<username>[^`!@#$^&*()+=,:;'"{}\|\[\]\s\/\\]+)(?::(?<password>[^`!@#$^&*()+=,:;'"{}\|\[\]\s\/\\]+))?@)?(?:(?<ipv4>((?:(?:25[0-5]|2[0-4]\d|1?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|1?\d\d?)))|\[(?<ipv6>(?i)(?:[\da-f]{0,4}:){1,7}(?:(?<ipv4_in_ipv6>(?:(?:25[0-5]|2[0-4]\d|1?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|1?\d\d?))|[\da-f]{0,4}))\]|(?:(?<sub_domain>[^\s~`!@#$%^&*()_+=,.?:;'"{}\|\[\]\/\\]+\.)*(?<domain>[^\s~`!@#$%^&*()_+=,.?:;'"{}\|\[\]\/\\]+)(?<tld>\.[^\s~`!@#$%^&*()\-_+=,.?:;'"{}\|\[\]\/\\0-9]{2,})))+(?<port>:\d+)?(?:\/(?<path>\/?[^\s`@#$^&=.?"{}\\]+\/)*(?<file>[^\s`@#$^&=?"{}\/\\]+)?(?<query>\?[^\s`#$^"{}\\]+)*(?<fragment>#[^\s`$^&=?"{}\/\\]+)?)?" Local $sString = "# Quick Example (full)" & @CRLF & _ "https://uSer:pass@sub1.sub-2.EXamPle.uk.com:80/PATH1/paTh2?qUeRy=1&q2=2#ancHor" & @CRLF & _ "https://úser@suß.öctúvt.tìd/file-path/FILE_%82%8A.php?query=value&query2=value2#somethig" & @CRLF & _ "HTTP://دامنه.ایران/زیردامنه/زیردامنه۲/فایل.پسوند؟درخواست=جواب" & @CRLF & _ "http://blog.sergeys.us/beer?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+SergeySus+(Sergey+Sus+Photography+%C2%BB+Blog)&utm_content=Google+Reader" & @CRLF & _ "http://test.site/wp-admin/post.php?t=1347548645469?t=1347548651124?t=1347548656685?t=1347548662469?t=1347548672300?t=1347548681615?#sdfsdf" & @CRLF & _ "http://example.com/wp-admin/load-scripts.php?c=1&load[]=swfobject,jquery,utils&ver=3.5" & @CRLF & _ "http://video.google.co.uk:80/videoplay?docid=-7246927612831078230&hl=en#hello" & @CRLF & _ "https://example.com/path/resource.txt#fragment" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "# Basic" & @CRLF & _ "www.example.com" & @CRLF & _ "http://example.com" & @CRLF & _ "https://example.com" & @CRLF & _ "https://example.ac.eu" & @CRLF & _ "https://example.gov.ir" & @CRLF & _ "ftp://example.com" & @CRLF & _ "sftp://example.com" & @CRLF & _ "" & @CRLF & _ "# With Path" & @CRLF & _ "www.example.com/path1/path2/" & @CRLF & _ "http://example.com/path1/path2/" & @CRLF & _ "https://example.com/path1/path2" & @CRLF & _ "" & @CRLF & _ "# With Path & File" & @CRLF & _ "www.example.com/path1/path2/file.pdf" & @CRLF & _ "http://example.com/path1/path2/file.c" & @CRLF & _ "https://example.com/path1/path2/file.txt" & @CRLF & _ "" & @CRLF & _ "# With Path & Query" & @CRLF & _ "http://www.example.com/?query=some-path/path1/path2/" & @CRLF & _ "http://example.com/path1/path2/?query=something" & @CRLF & _ "https://example.com/path1/path2?query=something" & @CRLF & _ "" & @CRLF & _ "# With Subdomain" & @CRLF & _ "sub1.sub2.example.com" & @CRLF & _ "www.example.com" & @CRLF & _ "http://www.example.com" & @CRLF & _ "ftp://sub1.example.com" & @CRLF & _ "" & @CRLF & _ "# With Port" & @CRLF & _ "www.example.com:80" & @CRLF & _ "http://example.com:8080" & @CRLF & _ "ftp://example.com:21" & @CRLF & _ "ftp://sub1.example.com:21" & @CRLF & _ "http://example.com:8080/path1/path2/" & @CRLF & _ "http://example.com:80/path1/path2/file.c" & @CRLF & _ "http://example.com:443/path1/path2/?query=something" & @CRLF & _ "" & @CRLF & _ "# With Username" & @CRLF & _ "user@example.com" & @CRLF & _ "http://user@www.example.com" & @CRLF & _ "ftp://user@example.com" & @CRLF & _ "ftp://user@sub1.example.com:21" & @CRLF & _ "http://user@example.com:8080/path1/path2/" & @CRLF & _ "http://user@example.com/path1/path2/file.c" & @CRLF & _ "http://user@example.com/path1/path2/?query=something" & @CRLF & _ "" & @CRLF & _ "# Some Crazy Examples" & @CRLF & _ "http://ヒキワリ.ナットウ.ニホン" & @CRLF & _ "sip://ßàÁâãóôþüúðæåïçèõöÿýòäœêëìíøù.îûñé" & @CRLF & _ "HTTP://دامنه.ایران/زیردامنه/زیردامنه۲/فایل.پسوند؟درخواست=جواب" & @CRLF & _ "http://example.com/wp-admin/load-scripts.php?c=1&load[]=swfobject,jquery,utils&ver=3.5" & @CRLF & _ "https://úser@sub1.suß2.sub3.öctúvt.tìd.tìd/V3/file-path/P----29BSx_A_%82%8A_D_M1n_a.php?query=value#somethig" & @CRLF & _ "http://www.go.com.au/ersdfs?dfd=dfgd@s=1" & @CRLF & _ "https://uSer@EXamPle.uk.com:80/?qyery?qUeRy=1&q2=2#ancHor" & @CRLF & _ "http://example.com/%E5%BC%95%E3%81%8D%E5%89%B2%E3%82%8A.html" & @CRLF & _ "hTTp://eXamPLE.CoM" & @CRLF & _ "https://belgië.be" & @CRLF & _ "https://belgië.be.gov" & @CRLF & _ "http://user@[2001:db8::1]/" & @CRLF & _ "https://user@111.222.33.44:49171/Cda-cgi/clientcgi?action=start" & @CRLF & _ "http://[2001:db8::1]:80" & @CRLF & _ "a2d.dd4d.d5d.www.go.com.au" & @CRLF & _ "a.b.c.d.e.go.com.co.uk" & @CRLF & _ "go.com.uk" & @CRLF & _ "go.go.com" & @CRLF & _ "1go-co.com" & @CRLF & _ "1-2-3-4--5-go.com" & @CRLF & _ "www.go.com.au" & @CRLF & _ "" & @CRLF & _ "# These Should not be Seen as Domain" & @CRLF & _ "example.c" & @CRLF & _ "example..com" & @CRLF & _ "123.b" & @CRLF & _ "go.12" & @CRLF & _ "1.2.3.4" & @CRLF & _ "ff:ff:ff:ff" & @CRLF & _ "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" & @CRLF & _ "hTTps://111.222.533.44:49171/cda-cgi/clientcgi?action=start" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "# These Should be Seen Partially" & @CRLF & _ "//example.com.c" & @CRLF & _ "example.com.c" & @CRLF & _ "http://example.com.com." & @CRLF & _ "" & @CRLF & _ "# It Should Find URLs in a Text too" & @CRLF & _ "create Share Links to send your expressions to co-workers or link to them on Twitter or your blog [ex. http://RegExr.com?2rjl655] " & @CRLF & _ "Built by gskinner.com with Flex 3 [adobe.com/go/flex] and Spelling Plus Library for text highlighting[gskinner.com/products/spl]." & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "# Resources" & @CRLF & _ "- https://en.wikipedia.org/wiki/Uniform_Resource_Identifie" & @CRLF & _ "- https://en.wikipedia.org/wiki/List_of_URI_schemes" & @CRLF & _ "- " & @CRLF & _ "- https://zencoder.support.brightcove.com/general-information/special-characters-usernames-and-passwords.html" & @CRLF & _ "- https://support.microsoft.com/en-us/topic/certain-special-characters-are-not-allowed-in-the-url-entered-into-the-address-bar-of-internet-explorer-a8e2a966-19d6-27af-06cc-e720f25e8b02" & @CRLF & _ "- https://perishablepress.com/stop-using-unsafe-characters-in-urls/" & @CRLF & _ "- https://help.dragonmetrics.com/en/articles/213986-invalid-characters-in-url" 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