Regular Expressions 101

Save & Manage Regex

  • Current Version: 2
  • 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

$re = '/^((?<atu>ATU)|(?<be>BE)|(?<bg>BG)|(?<cy>CY)|(?<cz>CZ)|(?<dk>DK)|(?<de>DE)|(?<ee>EE)|(?<el>EL)|(?<es>ES)|(?<fi>FI)|(?<fr>FR)|(?<hr>HR)|(?<hu>HU)|(?<ie>IE)|(?<lt>LT)|(?<lu>LU)|(?<lv>LV)|(?<mt>MT)|(?<nl>NL)|(?<pl>PL)|(?<pt>PT)|(?<ro>RO)|(?<se>SE)|(?<si>SI)|(?<sk>SK)|(?<xi>XI))((?(atu)[0-9]{8})|(?(be)[01][0-9]{9})|(?(bg)[0-9]{9,10})|(?(cy)[A-Z0-9]{9})|(?(cz)[0-9]{8,10})|(?(dk)[0-9]{8})|(?(de)[0-9]{9})|(?(ee)[0-9]{9})|(?(el)[0-9]{9})|(?(es)[A-Z]{1}[0-9]{8})|(?(fi)[0-9]{8})(?(fr)[0-9A-Z]{2}[0-9]{9})|(?(hr)[0-9]{11})|(?(hu)[0-9]{8})|(?(ie)(?:[0-9]{7}[A-Z]{1,2}|[0-9][A-Z][0-9]{5}[A-Z]))|(?(lt)(?:[0-9]{9}|[0-9]{12}))|(?(lu)[0-9]{8})|(?(lv)[0-9]{11})(?(mt)[0-9]{8})(?(nl)[0-9]{9}B[0-9]{2})|(?(pl)[0-9]{10})|(?(pt)[0-9]{9})|(?(ro)[0-9]{2,10})|(?(se)[0-9]{12})|(?(si)[0-9]{8})|(?(sk)[0-9]{10})|(?(xi)(?:[0-9]{3}[0-9]{4}[0-9]{2}(?:[0-9]{3})?|[A-Z0-9]{5})))$/m'; $str = 'ATU99999999 BE0999999999 BE1999999999 BG999999999 BG9999999999 CY99999999L CZ99999999 CZ999999999 CZ9999999999 DE999999999 DK99999999 EE999999999 EL999999999 ESX12345678 FI99999999 FRXX999999999 HR99999999999 HU99999999 IE9S99999L IE9999999WI LT999999999 LT999999999999 LU99999999 LV99999999999 MT99999999 NL000099998B57 PL9999999999 PT999999999 RO999999999 SE999999999999 SI99999999 SK9999999999 XI999999999 XI999999999999 XIGD999 XIHA999'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php