Regular Expressions 101

Save & Share

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

re = /^(?:((?: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}))$ /m str = 'AD1400080001001234567890 AT483200000012345864 BE71096123456769 BG18RZBB91550123456789 HR1723600001101234565 CY21002001950000357001234567 CZ5508000000001234567899 DK9520000123456789 EE471000001020145685 FI1410093000123458 FR7630006000011234567890189 DE75512108001245126199 GI04BARC000001234567890 GR9608100010000001234567890 HU93116000060000000012345676 IS750001121234563108962099 IE64IRCE92050112345678 IT60X0542811101000000123456 LV97HABA0012345678910 LI7408806123456789012 LT601010012345678901 LU120010001234567891 MT31MALT01100000000000000000123 MC5810096180790123456789085 NL02ABNA0123456789 NO8330001234567 PL10105000997603123456789123 PT50002700000001234567833 RO09BCYP0000001234567890 SM76P0854009812123456789123 SK8975000000000012345671 SI56192001234567892 ES7921000813610123456789 SE7280000810340009783242 CH5604835012345678009 GB33BUKB20201555555555 VA59001123000012345678 AL35202111090000000001234567 AZ96AZEJ00000000001234567890 BH02CITI00001077181611 BA393385804800211234 BR1500000000000010932840814P2 CR23015108410026012345 FO9264600123456789 GL8964710123456789 DO22ACAU00000000000123456789 EG800002000156789012345180002 GE60NB0000000123456789 GT20AGRO00000000001234567890 IL170108000000012612345 JO71CBJO0000000000001234567890 KZ563190000012344567 XK051212012345678906 KW81CBKU0000000000001234560101 LB92000700000000123123456123 MK07200002785123453 MR1300020001010000123456753 MU43BOMM0101123456789101000MUR MD21EX000000000001234567 ME25505000012345678951 PK36SCBL0000001123456702 PS92PALS000000000400123456702 QA54QNBA000000000000693123456 LC14BOSL123456789012345678901234 ST23000200000289355710148 SA4420000001234567891234 RS35105008123123123173 TL380010012345678910106 TN5904018104004942712345 TR320010009999901234567890 AE460090000000123456789 VG21PACG0000000123456789 UA903052992990004149123456789 SC52BAHL01031234567890123456USD IQ20CBIQ861800101010500 BY86AKBB10100000002966000000 SV43ACAT00000000000000123123 LY38021001000000123456789 SD8811123456789012 test' # Print the match result str.scan(re) do |match| puts match.to_s end

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html