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
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

Code Generator

Generated Code

import re regex = re.compile((r"^(?:((?:IT|SM)\d{2}[A-Z]{1}\d{22})|(NL\d{2}[A-Z]{4}\d{10})|(LV\d{2}[A-Z]{4}\d{13})|((?:BG|GB|IE)\d{2}[A-Z]{4}\d{14})|(GI\d{2}[A-Z]{4}\d{15})|(RO\d{2}[A-Z]{4}\d{16})|(MT\d{2}[A-Z]{4}\d{23})|(NO\d{13})|((?:DK|FI)\d{16})|((?:SI)\d{17})|((?:AT|EE|LU|LT)\d{18})|((?:HR|LI|CH)\d{19})|((?:DE|VA)\d{20})|((?:AD|CZ|ES|MD|SK|SE)\d{22})|(PT\d{23})|((?:IS)\d{24})|((?:BE)\d{14})|((?:FR|MC|GR)\d{25})|((?:PL|HU|CY)\d{26}))$\n"), flags=re.MULTILINE) test_str = ("AD1400080001001234567890\n" "AT483200000012345864\n" "BE71096123456769\n" "BG18RZBB91550123456789\n" "HR1723600001101234565\n" "CY21002001950000357001234567\n" "CZ5508000000001234567899\n" "DK9520000123456789\n" "EE471000001020145685\n" "FI1410093000123458\n" "FR7630006000011234567890189\n" "DE75512108001245126199\n" "GI04BARC000001234567890\n" "GR9608100010000001234567890\n" "HU93116000060000000012345676\n" "IS750001121234563108962099\n" "IE64IRCE92050112345678\n" "IT60X0542811101000000123456\n" "LV97HABA0012345678910\n" "LI7408806123456789012\n" "LT601010012345678901\n" "LU120010001234567891\n" "MT31MALT01100000000000000000123\n" "MC5810096180790123456789085\n" "NL02ABNA0123456789\n" "NO8330001234567\n" "PL10105000997603123456789123\n" "PT50002700000001234567833\n" "RO09BCYP0000001234567890\n" "SM76P0854009812123456789123\n" "SK8975000000000012345671\n" "SI56192001234567892\n" "ES7921000813610123456789\n" "SE7280000810340009783242\n" "CH5604835012345678009\n" "GB33BUKB20201555555555\n" "VA59001123000012345678\n\n" "AL35202111090000000001234567\n" "AZ96AZEJ00000000001234567890\n" "BH02CITI00001077181611\n" "BA393385804800211234\n" "BR1500000000000010932840814P2\n" "CR23015108410026012345\n" "FO9264600123456789\n" "GL8964710123456789\n" "DO22ACAU00000000000123456789\n" "EG800002000156789012345180002\n" "GE60NB0000000123456789\n" "GT20AGRO00000000001234567890\n" "IL170108000000012612345\n" "JO71CBJO0000000000001234567890\n" "KZ563190000012344567\n" "XK051212012345678906\n" "KW81CBKU0000000000001234560101\n" "LB92000700000000123123456123\n" "MK07200002785123453\n" "MR1300020001010000123456753\n" "MU43BOMM0101123456789101000MUR\n" "MD21EX000000000001234567\n" "ME25505000012345678951\n" "PK36SCBL0000001123456702\n" "PS92PALS000000000400123456702\n" "QA54QNBA000000000000693123456\n" "LC14BOSL123456789012345678901234\n" "ST23000200000289355710148\n" "SA4420000001234567891234\n" "RS35105008123123123173\n" "TL380010012345678910106\n" "TN5904018104004942712345\n" "TR320010009999901234567890\n" "AE460090000000123456789\n" "VG21PACG0000000123456789\n" "UA903052992990004149123456789\n" "SC52BAHL01031234567890123456USD\n" "IQ20CBIQ861800101010500\n" "BY86AKBB10100000002966000000\n" "SV43ACAT00000000000000123123\n" "LY38021001000000123456789\n" "SD8811123456789012\n\n" "test") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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 Python, please visit: https://docs.python.org/3/library/re.html