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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/

Test String

Code Generator

Generated Code

$re = '/(-- iOS 8\.2 --)\G|.(?:iPhone 4s.\((.*?)\))/'; $str = '== Device Types == iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s) iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5) iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s) iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus) iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6) iPad 2 (com.apple.CoreSimulator.SimDeviceType.iPad-2) iPad Retina (com.apple.CoreSimulator.SimDeviceType.iPad-Retina) iPad Air (com.apple.CoreSimulator.SimDeviceType.iPad-Air) Resizable iPhone (com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone) Resizable iPad (com.apple.CoreSimulator.SimDeviceType.Resizable-iPad) == Runtimes == iOS 8.1 (8.1 - 12B411) (com.apple.CoreSimulator.SimRuntime.iOS-8-1) iOS 8.2 (8.2 - 12D508) (com.apple.CoreSimulator.SimRuntime.iOS-8-2) == Devices == -- iOS 8.1 -- iPhone 4s (F05C1130-5F17-483C-8545-41DB60BD6729) (Shutdown) -- iOS 8.2 -- iPhone 4s (F05C1130-5F17-483C-8545-41DB60BD6729) (Shutdown) iPhone 5 (6A9974F3-4C46-4583-9D74-A1083E76CCB9) (Shutdown) iPhone 5s (89547F56-69D0-4696-98F5-9C4AF58BEC08) (Shutdown) iPhone 6 Plus (AD19FA1E-4091-44D7-900E-E9BDF6E22460) (Shutdown) iPhone 6 (6D639171-D599-43E9-BFCF-CD2765CE4DEE) (Booted) iPad 2 (C8A1DF07-27D9-467F-BBCC-C76695C81BD0) (Shutdown) iPad Retina (3ED6ED7E-D173-4C50-88EB-AB2F1CCA30D0) (Shutdown) iPad Air (9FF89D26-305F-4BBF-8BC6-90BB2AE4C424) (Shutdown) Resizable iPhone (C4BC5922-316C-4176-96FE-8FE2B066C1FD) (Shutdown) Resizable iPad (DCF07107-4FD4-4B77-A531-0B652F6C1C61) (Shutdown) -- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-3 -- iPhone 4s (F88A4DF6-3B81-445D-A296-73CC69CE7FE6) (Shutdown) (unavailable, runtime profile not found) iPhone 5 (ED535FC5-34CE-43B4-ABCA-C57093F7D8FF) (Shutdown) (unavailable, runtime profile not found) iPhone 5s (7CFE4925-328E-483E-B137-996520446291) (Shutdown) (unavailable, runtime profile not found) iPhone 6 Plus (1BAD21C1-33B8-49A1-90F1-6C9C4FDDDE4B) (Shutdown) (unavailable, runtime profile not found) iPhone 6 (3EDA5D17-001B-49CD-83A6-7E1A3926CB28) (Shutdown) (unavailable, runtime profile not found) iPad 2 (EA7BBF7B-CFA1-49A6-A84D-471F31E832B8) (Shutdown) (unavailable, runtime profile not found) iPad Retina (52B69DBB-352A-49C9-9B56-8EEB463DD023) (Shutdown) (unavailable, runtime profile not found) iPad Air (CF60978F-52EF-4E12-8B63-02BEA30D1702) (Shutdown) (unavailable, runtime profile not found) Resizable iPhone (903870E3-FF55-48BB-953F-26CCBAFE5E45) (Shutdown) (unavailable, runtime profile not found) Resizable iPad (C447F468-2FCE-4731-8CAA-86922F8002CC) (Shutdown) (unavailable, runtime profile not found)'; preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 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