Regular Expressions 101

Save & Share

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 = '/(?:[ebay]*(?:[\/]|[itm=])|^)([0-9]{9,12})/'; $str = '221690103652 http://www.ebay.co.uk/itm/HP-OVU422000-06-MEDIA-CENTER-REMOTE-IR-USB-RECEIVER-/161830504761?ssPageName=STRK:MESE:IT http://www.ebay.co.uk/itm/like/Classic-1985-Porsche-944-2-5-EXCELLENT-CONDITION-TONS-OF-HISTORY-PART-EX/252112320478?hlpht=true&ops=true&viphx=1&_trksid=p5197.c100068.m2280&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D20140211130857%26meid%3D73e99323141844c18d88a2debd9c2309%26pid%3D100068%26rk%3D1%26rkt%3D6%26mehot%3Dpp%26sd%3D121776622006%26clkid%3D276267228855363952&_qi=RTM2063753 http://www.ebay.co.uk/itm/like/PORSCHE-911-CARRERA-SC-3-0-TARGA-SLATE-NOSE-LHD-Turbo-body-tyres-345-35-15/201440886841?hlpht=true&ops=true&viphx=1&_trksid=p5197.c100068.m2280&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D20140211130857%26meid%3D2a0f8e2eb452470d930e2a8baf81f305%26pid%3D100068%26rk%3D2%26rkt%3D6%26mehot%3Dpp%26sd%3D121776622006%26clkid%3D276277477609057080&_qi=RTM2063756 http://www.ebay.co.uk/itm/201440886841 http://www.ebay.co.uk/itm/Honda-ANF-Innova-125-3-/301757710737?&_trksid=p2056016.l4276 http://www.ebay.co.uk/itm/171921735372?_trksid=p2057872.m2749.l2648&var=470833174734&ssPageName=STRK%3AMEBIDX%3AIT http://www.ebay.co.uk/itm/Revell-1-24-Porsche-918-Spyder-New-Plastic-Model-Kit-07026-1-24/181888674810?_trksid=p2047675.c100011.m1850&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D33662%26meid%3Ded9c952f46664e5c93a9b54e6aea0368%26pid%3D100011%26rk%3D4%26rkt%3D10%26sd%3D221869196497 http://www.ebay.co.uk/rcm/v1/Italeri-1-72-1236-FRS-1-SEA-HARRIER-AIRCRAFT-KIT-/?itm=131606934520&_trksid=p2047675.c100010.m1843 http://www.ebay.co.uk/itm/Vauxhall-Opel-Corsa-1-2i-16v-2003-Elegance-SILVER-AIR-CON-/221690103652 221690103652 '; 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