Regular Expressions 101

Save & Share

  • Regex Version: ver. 8
  • 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 = '/[\s*<]+\d+$|[\s*<]+(?![A-Z]{6}.*)\w*\d[\w>]*$|\d{6,}$|[\s*<]+[A-Z]{6}$|(?![A-Z]+$)(?<=[A-Z])\w{6}$/m'; $str = 'Norton *AP1223506209 --> Norton *AP or Norton Norton *AP1223506209 Norton *AP1223511428 Norton AP1223511428 EUROWINGS VYJD6J_123001 --> EUROWINGS EUROWINGS VYJD6J_123001 EUROWINGS W6PDFI_125626 AER LINGUCB22QKM2 --> AER LINGU or AER LINGUCB AER LINGUCB22QKM2 AER LINGUCB248L2W FACEBK *YPEVCCSS32 AIR FRANCE JWNCSC --> AIR FRANCE AIR FRANCE JWNCSC AIR FRANCE K8L7TT PAYPAL *AIRBNB HMQXBW --> PAYPAL *AIRBNB PAYPAL *AIRBNB HMQXBW PAYPAL *AIRBNB HMQXNZ SAS 1174565172360 --> SAS SAS 1174565172360 SAS 1174565172368 EASYJET 000ESJ5K38 --> EASYJET EASYJET 000ESJ5K38 EASYJET 000ESJ5R4C EASYJET 000ESJ5TWN EASYJET 000ESJ5V86 EASYJET 000ESJ5XZ3 Emirates Group 210003513 --> Emirates Group Emirates Group 210003513 Emirates Group 210003539 Emirates Group 210003547 EMP Merchan --> EMP Merchan EMP Merchan 014354B77F00 --> EMP Merchan EMP Merchan 014354B77F00 EMP Merchan 092F7CC07F00 EMP Merchan 0CD6FC9E7F00 MSFT *<E08003YV1E> --> MSFT or MSFT * MSFT *<E08003YV1E> MSFT *<E08003YW6W> MSFT *<E08003YYYG> MSFT *<E08003ZB5F> FACEBK *YNWF9CEQM2 --> FACEBK or FACEBK * FACEBK *YNWF9CEQM2 FACEBK *YPBT3DNMM2 FACEBK *YPEVCCSS32 PAYPAL *NITS SHOP --> PAYPAL *NITS SHOP PAYPAL *NITS SHOP PAYPAL *NITSCHKE PAYPAL *NITSCHKEGMB PAYPAL *NITTYGRITTY PAYPAL *NITZSCHKE GOOGLE *SmileyGamer --> GOOGLE *SmileyGamer GOOGLE *SmileyGamer GOOGLE *Smoke Free GOOGLE *SMP LLC --> GOOGLE *SMP LLC (or GOOGLE *SMP) GOOGLE *SMP LLC Spotify P018792946 --> Spotify Spotify P018792946 Spotify P0187942C2 Spotify P018796B86 HOTELS.COM137671668500 --> HOTELS.COM HOTELS.COM137671668500 HOTELS.COM137671798182 HOTELS.COM137673795909 Etsy.com - FJSWIM --> Etsy.com Etsy.com - FJSWIM Etsy.com - fluoshop Etsy.com - FolkTalesPl'; 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