Regular Expressions 101

Save & Share

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

/
/
gi

Test String

Code Generator

Generated Code

$re = '/[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}/i'; $str = 'Uxbridge Road, Southall UB1 3HH, United Kingdom Richmond TW9 1QJ, United Kingdom CF24 3DG SW6 1AA NW10 6RB W11 3SJ W11 3SJ NW3 6LU NW10 6RB EC1A 9JX WC2A #Order for 671500 27 Newman\'s Row London WC2A 2 West Smithfield London EC1A 9JX EC1A 9JX N1 6BS EC1A 9JX WC2H 0EB WC1X 8LT N1 0NY NW10 6RB BS98 1TL TV Licensing[44] BX1 1LT Lloyds Bank formerly known as Lloyds TSB Bank[45] – non-geographic address BX2 1LB Bank of Scotland (part of Lloyds Banking Group)[46] – non-geographic address BX3 2BB Barclays Bank[47] – non-geographic address BX4 7SB TSB Bank BX5 5AT VAT Central Unit of HM Revenue and Customs[48] (Roman numeral "VAT" = "5AT") – non-geographic address CF10 1BH Lloyds Banking Group (formerly Black Horse Finance) CF99 1NA National Assembly for Wales CV4 8UW University of Warwick CV35 0DB Aston Martin after their long line of iconic sports cars that bear the "DB" moniker DA1 1RT Dartford F.C. (nicknamed The Darts) DE99 3GG Egg Banking DE55 4SW Slimming World DH98 1BT British Telecom DH99 1NS National Savings certificates administration E14 5HQ HSBC headquarters E16 1XL ExCeL London[49] E20 2AQ Olympic Aquatics Centre E20 2BB Olympic Basketball Arena E20 2ST Olympic Stadium E20 3BS Olympic Broadcast Centre E20 3EL Olympic Velodrome E20 3ET Olympic Eton Manor Tennis Courts E20 3HB Olympic Handball Arena E20 3HY Olympic Hockey Stadium E98 1SN The Sun newspaper E98 1ST The Sunday Times newspaper E98 1TT The Times newspaper EC2N 2DB Deutsche Bank EC4Y 0HQ Royal Mail Group Ltd headquarters EH12 1HQ Royal Bank of Scotland headquarters EH99 1SP Scottish Parliament[50] (founded in 1999) G58 1SB National Savings Bank (the district number 58 also approximates the outline of the initials SB) GIR 0AA Girobank (now Santander Corporate Banking) IV21 2LR Two Lochs Radio L30 4GB Girobank (alternative geographic postcode) LS98 1FD First Direct bank N1 9GU The Guardian newspaper N81 1ER Electoral Reform Services[40][51] NE1 4ST St James\' Park Stadium, Newcastle United NG80 1EH Experian Embankment House NG80 1LH Experian Lambert House NG80 1RH Experian Riverleen House NG80 1TH Experian Talbot House PH1 5RB Royal Bank of Scotland Perth Chief Office PH1 2SJ St Johnstone Football Club S2 4SU Sheffield United Football Club S6 1SW Sheffield Wednesday Football Club S14 7UP The World Snooker Championships at the Crucible Theatre, Sheffield;[52] 147 UP refers to a maximum lead (from a maximum break) in snooker SA99 Driver and Vehicle Licensing Agency All postcodes starting with SA99 are for the DVLA offices in the Morriston area of Swansea, the final part of the postcode relates to the specific office or department within the DVLA SE1 8UJ Union Jack Club SM6 0HB Homebase Limited SN38 1NW Nationwide Building Society SW1A 0AA House of Commons SW1A 0PW House of Lords (Palace of Westminster; see above for House of Commons) SW1A 1AA Buckingham Palace (the Monarch) SW1A 2AA 10 Downing Street (the Prime Minister) SW1A 2AB 11 Downing Street (Chancellor of the Exchequer) SW1H 0TL Transport for London (Windsor House, 50 Victoria Street) SW1P 3EU European Commission and European Parliament office (European Union) SW1W 0DT The Daily Telegraph newspaper TW8 9GS GlaxoSmithKline W1A 1AA BBC Broadcasting House W1D 4FA Betgenius, the former address of The Football Association W1N 4DJ BBC Radio 1 (disc jockey) '; 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