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

/
/
g

Test String

Code Generator

Generated Code

re = /(?:IT|SM)\d{2} ?[A-Z]\d{3}(?: ?\d{4}){4} ?\d{3}| CY\d{2} ?[A-Z]\d{3}(?: ?\d{4}){5}| NL\d{2} ?[A-Z]{4}(?: ?\d{4}){2} ?\d{2}| LV\d{2} ?[A-Z]{4}(?: ?\d{4}){3} ?\d| (?:BG|BH|GB|IE)\d{2} ?[A-Z]{4}(?: ?\d{4}){3} ?\d{2}| GI\d{2} ?[A-Z]{4}(?: ?\d{4}){3} ?\d{3}| RO\d{2} ?[A-Z]{4}(?: ?\d{4}){4}| KW\d{2} ?[A-Z]{4}(?: ?\d{4}){5} ?\d{2}| MT\d{2} ?[A-Z]{4}(?: ?\d{4}){5} ?\d{3}| NO\d{2}(?: ?\d{4}){4}| (?:DK|FI|GL|FO)\d{2}(?: ?\d{4}){3} ?\d{2}| MK\d{2}(?: ?\d{4}){3} ?\d{3}| (?:AT|EE|KZ|LU|XK)\d{2}(?: ?\d{4}){4}| (?:BA|HR|LI|CH|CR)\d{2}(?: ?\d{4}){4} ?\d| (?:GE|DE|LT|ME|RS)\d{2}(?: ?\d{4}){4} ?\d{2}| IL\d{2}(?: ?\d{4}){4} ?\d{3}| (?:AD|CZ|ES|MD|SA)\d{2}(?: ?\d{4}){5}| PT\d{2}(?: ?\d{4}){5} ?\d| (?:BE|IS)\d{2}(?: ?\d{4}){5} ?\d{2}| (?:FR|MR|MC)\d{2}(?: ?\d{4}){5} ?\d{3}| (?:AL|DO|LB|PL)\d{2}(?: ?\d{4}){6}| (?:AZ|HU)\d{2}(?: ?\d{4}){6} ?\d| (?:GR|MU)\d{2}(?: ?\d{4}){6} ?\d{2}/ str = 'IT12 A123 1234 1234 1234 1234 123 IT12A1231234123412341234123 CY12 A123 1234 1234 1234 1234 1234 CY12A12312341234123412341234 NL12 ABCD 1234 1234 12 NL12ABCD1234123412 LV12 ABCD 1234 1234 1234 1 LV12ABCD1234123412341 BG12 ABCD 1234 1234 1234 12 BG12ABCD12341234123412 GI12 ABCD 1234 1234 1234 123 GI12ABCD123412341234123 RO12 ABCD 1234 1234 1234 1234 RO12ABCD1234123412341234 KW12 ABCD 1234 1234 1234 1234 1234 12 KW12ABCD1234123412341234123412 MT12 ABCD 1234 1234 1234 1234 1234 123 MT12ABCD12341234123412341234123 NO12 1234 1234 1234 1234 NO121234123412341234 DK12 1234 1324 1234 12 DK1212341324123412 MK12 1234 1234 1234 123 MK12123412341234123 AT12 1234 1234 1234 1234 AT121234123412341234 BA12 1234 1234 1234 1234 1 BA1212341234123412341 DE12 1234 1234 1234 1234 12 DE12123412341234123412 IL12 1234 1234 1234 1234 123 IL121234123412341234123 CZ12 1234 1234 1234 1234 1234 CZ1212341234123412341234 PT12 1234 1234 1234 1234 1234 1 PT12123412341234123412341 BE12 1234 1234 1234 1234 1234 12 BE121234123412341234123412 FR12 1234 1234 1234 1234 1234 123 FR1212341234123412341234123 AL12 1234 1234 1234 1234 1234 1234 AL12123412341234123412341234 AZ12 1234 1234 1234 1234 1234 1234 1 AZ121234123412341234123412341 GR12 1234 1234 1234 1234 1234 1234 12 GR1212341234123412341234123412' # 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