Regular Expressions 101

Save & Share

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

/
/
gmx

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 = "(?mx)(?(DEFINE)" & @CRLF & _ " (?<separator>\D?)" & @CRLF & _ " (?<iin> # issuer identification number for 16 and 19 digit cards" & @CRLF & _ " # MIR" & @CRLF & _ " 220[0-4]" & @CRLF & _ "" & @CRLF & _ " # Mastercard" & @CRLF & _ " | 222[1-9]" & @CRLF & _ " | 22[3-9]\d" & @CRLF & _ " | 2[3-6]\d{2}" & @CRLF & _ " | 27[01]\d" & @CRLF & _ " | 2720" & @CRLF & _ " | 5[1-5]\d{2}" & @CRLF & _ "" & @CRLF & _ " # JCB" & @CRLF & _ " | 352[89]" & @CRLF & _ " | 35[3-8]\d" & @CRLF & _ "" & @CRLF & _ " # Visa" & @CRLF & _ " | 4\d{3}" & @CRLF & _ "" & @CRLF & _ " # Dankort" & @CRLF & _ " | 5019" & @CRLF & _ "" & @CRLF & _ " # Discover" & @CRLF & _ " | 6011" & @CRLF & _ " | 622[1-9]" & @CRLF & _ " | 64[4-9]\d" & @CRLF & _ " | 65\d{2}" & @CRLF & _ "" & @CRLF & _ " # InterPayment" & @CRLF & _ " | 63[7-9]\d" & @CRLF & _ "" & @CRLF & _ " # UnionPay" & @CRLF & _ " | 62\d{2}" & @CRLF & _ "" & @CRLF & _ " # Maestro" & @CRLF & _ " | 5[06-9]\d{2}" & @CRLF & _ " | 6\d{3}" & @CRLF & _ "" & @CRLF & _ " # Troy" & @CRLF & _ " | 9792" & @CRLF & _ " )" & @CRLF & _ ")" & @CRLF & _ "" & @CRLF & _ "## pattern begins here" & @CRLF & _ "\b" & @CRLF & _ "(?| " & @CRLF & _ " (?: # 14 digits: XXXX-XXXXXX-XXXX" & @CRLF & _ " # Diners Club" & @CRLF & _ " (?: " & @CRLF & _ " 30[0-5]\d" & @CRLF & _ " | 36\d{2}" & @CRLF & _ " )" & @CRLF & _ " (?<sep>(?&separator))" & @CRLF & _ " \d{6}" & @CRLF & _ " \k<sep>" & @CRLF & _ " \d{4}" & @CRLF & _ " )" & @CRLF & _ " | (?: # 15 digits: XXXX-XXXXXX-XXXXX" & @CRLF & _ " # American Express" & @CRLF & _ " 3[47]\d{2}" & @CRLF & _ " (?<sep>(?&separator))" & @CRLF & _ " \d{6}" & @CRLF & _ " \k<sep>" & @CRLF & _ " \d{5}" & @CRLF & _ " )" & @CRLF & _ " | (?: # 16 digits: XXXX-XXXX-XXXX-XXXX" & @CRLF & _ " (?&iin)" & @CRLF & _ " (?<sep>(?&separator))" & @CRLF & _ " \d{4}" & @CRLF & _ " \k<sep>" & @CRLF & _ " \d{4}" & @CRLF & _ " \k<sep>" & @CRLF & _ " \d{4}" & @CRLF & _ " )" & @CRLF & _ " | (?: # 19 digits: XXXXXXXXXXXXXXXXXXX" & @CRLF & _ " (?&iin)" & @CRLF & _ " \d{15}" & @CRLF & _ " )" & @CRLF & _ ")" & @CRLF & _ "\b" Local $sString = "VISA:" & @CRLF & _ "4916-0964-6896-0680,4716 4897 5598 3394 4024007191458214;4929677677283453911" & @CRLF & _ "MasterCard:" & @CRLF & _ "5324-3523-3637-8594 2221 0059 1411 2881 2720993802486259" & @CRLF & _ "American Express (AMEX):" & @CRLF & _ "3417-364760-63463" & @CRLF & _ "3703,747943,64738" & @CRLF & _ "345620254969461" & @CRLF & _ "Discover:" & @CRLF & _ "6011;1100;7456;3157" & @CRLF & _ "6011|3448|8657|7515" & @CRLF & _ "6011549504486287170" & @CRLF & _ "JCB:" & @CRLF & _ "3535#1626#1193#3330" & @CRLF & _ "3537w2194w6345w7160" & @CRLF & _ "3544115541621080497" & @CRLF & _ "Diners Club - North America:" & @CRLF & _ "5550@6773@7664@9628" & @CRLF & _ "5498!9120!2137!8785" & @CRLF & _ "5418926330224156" & @CRLF & _ "Diners Club - Carte Blanche:" & @CRLF & _ "3038~338630~9862" & @CRLF & _ "3043 979928 4843" & @CRLF & _ "30514730539784" & @CRLF & _ "Diners Club - International:" & @CRLF & _ "3601-529450-0216" & @CRLF & _ "3684 740236 6092" & @CRLF & _ "36068539661053" & @CRLF & _ "Maestro:" & @CRLF & _ "5038-1482-6826-8317" & @CRLF & _ "6761 1161 5463 2772" & @CRLF & _ "5020976162959049" & @CRLF & _ "Visa Electron:" & @CRLF & _ "4175-0064-3983-6063" & @CRLF & _ "4844 2214 1640 8361" & @CRLF & _ "4508772794670888" & @CRLF & _ "InstaPayment:" & @CRLF & _ "6375-9237-0580-9744" & @CRLF & _ "6387 4000 3155 2203" & @CRLF & _ "6387679822589033" & @CRLF & _ "UnionPay:" & @CRLF & _ "6257-8903-9875-9366" & @CRLF & _ "6283348562159853" & @CRLF & _ "6234512468972678451" & @CRLF & _ "" & @CRLF & _ "Failed Luhn:" & @CRLF & _ "4024007191458216" & @CRLF & _ "4929677677283453917" & @CRLF & _ "Unrecognized IIN:" & @CRLF & _ "7135865572496322" & @CRLF & _ "3719865572496325" & @CRLF & _ "0139865572496321" & @CRLF & _ "7019865572496321" & @CRLF & _ "Improper spacing:" & @CRLF & _ "4024-0071 9145-8214" & @CRLF & _ "4024-00719145-8214" & @CRLF & _ "4024-007-19145-8214" & @CRLF & _ "3051-4730-5397-84" & @CRLF & _ "40240071914582144024007191458214" & @CRLF & _ "Unexpected length:" & @CRLF & _ "34562025496943" & @CRLF & _ "3498348562489555" & @CRLF & _ "305147305397847" & @CRLF & _ "3051473053978442" & @CRLF & _ "498348562489551" & @CRLF & _ "49834856248955837" & @CRLF & _ "498348562489558367" & @CRLF & _ "49834856248955836445" 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