Regular Expressions 101

Save & Share

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

/
/
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)^(?!.*?_.*?)(?!(?:[\w]+?\.)?\-[\w\.\-]*?)(?![\w]+?\-\.(?:[\w\.\-]+?))(?=[\w])(?=[\w\.\-]*?\.+[\w\.\-]*?)(?![\w\.\-]{254})(?!(?:\.?[\w\-\.]*?[\w\-]{64,}\.)+?)[\w\.\-]+?(?<![\w\-\.]*?\.[\d]+?)(?<=[\w\-]{2,})(?<![\w\-]{25})$" Local $sString = "# TEST" & @CRLF & _ "" & @CRLF & _ "## List of valid domains:" & @CRLF & _ "www.google.com" & @CRLF & _ "google.com" & @CRLF & _ "mkyong123.com" & @CRLF & _ "mkyong-info.com" & @CRLF & _ "sub.mkyong.com" & @CRLF & _ "sub.mkyong-info.com" & @CRLF & _ "mkyong.com.au" & @CRLF & _ "g.co" & @CRLF & _ "a.12E" & @CRLF & _ "mkyong.t.t.co" & @CRLF & _ "xn--stackoverflow.com" & @CRLF & _ "stackoverflow.xn--com" & @CRLF & _ "xn--d1ai6ai.xn--p1ai" & @CRLF & _ "stackoverflow.co.uk" & @CRLF & _ "a.xn--wgbh1c" & @CRLF & _ "1.2.3.4.com" & @CRLF & _ "x.XN--VERMGENSBERATUNG-PWB" & @CRLF & _ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com" & @CRLF & _ "www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com" & @CRLF & _ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com" & @CRLF & _ "" & @CRLF & _ "## List of invalid domains:" & @CRLF & _ "http://google.com" & @CRLF & _ "http://www.google.com" & @CRLF & _ "dot." & @CRLF & _ "space com" & @CRLF & _ "under_score.com" & @CRLF & _ "underscore.c_om" & @CRLF & _ "-dash.com" & @CRLF & _ "dash-.com" & @CRLF & _ "sub.-dash.com" & @CRLF & _ "sub-.dash.com" & @CRLF & _ "-.com" & @CRLF & _ "-com" & @CRLF & _ ".com" & @CRLF & _ "com" & @CRLF & _ "mx.gmail.com." & @CRLF & _ "mkyong.t.t.c" & @CRLF & _ "mkyong,com" & @CRLF & _ "mkyong.com/users" & @CRLF & _ "a.123" & @CRLF & _ "x.XN--VERMGENSBERATUNG-PWBB" & @CRLF & _ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkk.com" & @CRLF & _ "www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkk.co.uk" & @CRLF & _ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.comm" & @CRLF & _ "0123456789 +-.,!@#$%^&*();\\/|<>\"\'" & @CRLF & _ "12345 -98.7 3.141 .6180 9,000 +42" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "HELP" & @CRLF & _ "" & @CRLF & _ "https://github.com/c-hive/guides/blob/57cbbf72f1152214a160f9be8a57e2c4dc868cfd/etc/regex.md#domains" & @CRLF & _ "# allowed chars" & @CRLF & _ "[\w\d\.\-]" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "EXPLAIN" & @CRLF & _ "" & @CRLF & _ "# once upon a time..." & @CRLF & _ "^" & @CRLF & _ "# doesn't contain underscore (this is so that we can use \w alter on)" & @CRLF & _ "(?![\w\d\.\-]*?_[\w\d\.\-]*?)" & @CRLF & _ "# doesn't contain dash at the beginning of a label" & @CRLF & _ "(?!(?:[\d\w]+?\.)?\-[\w\d\.\-]*?)" & @CRLF & _ "# doesn't contain dash at the end of a label" & @CRLF & _ "(?![\w\d]+?\-\.(?:[\d\w\.\-]+?))" & @CRLF & _ "# starts with a non-limit char" & @CRLF & _ "(?=[\w\d\])" & @CRLF & _ "# contains at least 1 dot" & @CRLF & _ "(?=[\w\d\.\-]*?\.+[\w\d\.\-]*?)" & @CRLF & _ "# not longer than 253 chars" & @CRLF & _ "(?![\w\d\.\-]{253})" & @CRLF & _ "# doesn't contain a label longer than 63 char" & @CRLF & _ "(?!(?:\.?[\w\d\-\.]*?[\w\d\-]{64,}\.)+?)" & @CRLF & _ "# allowed chars" & @CRLF & _ "[\w\d\.\-]+?" & @CRLF & _ "# TLD is not digit-only" & @CRLF & _ "(?<![\w\d\-\.]*?\.[\d]+?)" & @CRLF & _ "# TLD is at least 2 characters" & @CRLF & _ "(?<=[\w\d\-]{2,})" & @CRLF & _ "# TLD is at most 24 characters" & @CRLF & _ "(?<![\w\d\-]{25})" & @CRLF & _ "# the end" & @CRLF & _ "&" 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