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 = '/(?im)^[^\S\r\n]*([^()\r\n]+?)[^\S\r\n]*(?:(\(.*?\)))?[^\S\r\n]*\(([a-f0-9]+(?:-[a-f0-9]+)*)\)[^\S\r\n]*(\(.*?\))/'; $str = 'iPhone 5s (B6780382-ADBC-4F92-B1CA-52111A5A6FBE) (Shutdown) iPhone 6 (FDA15891-2487-4C9E-A7F2-0E476C652E1D) (Shutdown) iPhone 6 Plus (58D4FC86-8E22-4995-816D-BC8799AE1220) (Shutdown) iPhone 6s (AE9BCF92-4814-4ABD-A791-FA60E0919156) (Shutdown) iPhone 6s Plus (5D431BB6-42AE-455D-8501-2227687D1A00) (Shutdown) iPhone 7 (0211256D-308F-4210-807D-DAAD02CC8AD9) (Shutdown) iPhone 7 Plus (872D5513-434C-4618-9350-A2AB77B04459) (Shutdown) iPhone 8 (74F7E423-1D17-475E-B18B-0FAAFC19DD0F) (Shutdown) iPhone 8 Plus (DB424FB3-6D34-4FE9-82AD-E50F439A47AD) (Shutdown) iPhone SE (ECF43B3D-38E1-4A37-8B07-C3CB72B14AE0) (Shutdown) iPhone X (40D45896-6325-4BB6-99D2-420E3472B68E) (Shutdown) iPhone Xs (5AAFEA8B-CE48-4DBE-9BAD-F9A714FAB4BA) (Shutdown) iPhone Xs Max (29946005-C6FF-4E77-98C4-A104917A9FD9) (Shutdown) iPhone Xʀ (205A5924-472E-4B83-AB7D-5FA56D93DC01) (Shutdown) iPad Air (3rd generation) (54CE7050-9D80-4000-87AC-D1717C3F5890) (Shutdown) iPad Air (83D98641-4FE8-476A-991E-14C0BF687DC6) (Shutdown) iPad Air 2 (E6951B0F-2DD3-4361-8469-BA319D1FACA9) (Shutdown) iPad (5th generation) (CB7A9551-9B29-4999-82A0-872C3700C316) (Shutdown) iPad Pro (9.7-inch) (98FEC483-DC9B-4092-896E-CB9E8F165E51) (Shutdown) iPad Pro (12.9-inch) (DD14F482-E456-4E6D-A044-C72818A7C52D) (Shutdown) iPad Pro (12.9-inch) (2nd generation) (8C8364BA-A85D-4B3D-AD30-B179CA7F4541) (Shutdown) iPad Pro (10.5-inch) (AA6DEE43-167D-42A4-9399-4727651BDAC7) (Shutdown) iPad (6th generation) (040A1950-770F-4DB0-BC0A-91237C23AAC6) (Shutdown) iPad Pro (11-inch) (07D97297-2E42-4FE8-B105-3245737D0CA3) (Shutdown) iPad Pro (12.9-inch) (3rd generation) (692172E8-2AFB-465A-AC0D-4109AF1679B5) (Shutdown) '; 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