Regular Expressions 101

Save & Share

  • Save new Regex
    ctrl+s
  • Update 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
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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/iPhone.*/m'; $str = 'iPhone 7 Plus iPad Pro 12.9 2015 iOS15.5 beta 4 iPhone 11 Pro iOS15.5 beta4 iPad Pro 10.5 2017 iPad 9.7 2018 iOS15.5 beta4 iPhone X iPhone 11 Pro Max iPad Pro 10.5 2017 iPad mini 3 iPhone X iPad Pro 12.9 2021 iPhone 13 iPhone 11 iPhone 12 mini iPad Pro 12.9 2018 iPad Pro 11 2018 iPhone 12 iPhone X iOS15.5 beta4 iPad Air 2 iPhone 8 iPhone 6 iPhone XS Max iPad mini 4 iPad Air 3 (2019) iPhone SE 2020 iPhone 11 Pro iPhone 12 Pro iPad Mini 2019 iPad 9.7 2018 iPad 10.2 2020 iPhone SE iPad Air 2 iPad Air 2022 5th Gen iPad Air 2020 iPad Air 2 iPad Pro 11 2021 iPhone SE 2020 iPhone 6 Plus iPad Pro 11 2020 iPad 10.2 2020 iPad Pro 10.5 2017 iPad 10.2 iPhone XR iPad Pro 12.9 2015 iPad Pro iPad Air 2 iPhone 7 iPad Mini 2021 6th Gen iPad Air 2020 iPhone 8 Plus iPhone 11 iPad 9.7 2017 5th Gen iPhone XS iPad Pro 12.9 2020 iPhone 6S iPad Air iPhone XS Max iPhone SE 2020 iPhone_11_Pro iPhone 5S iPhone 8 iPhone 7 Plus iPod Touch 6 iPad Pro 9.7 iPhone 12 mini iOS15.5 beta4 iPhone X iPhone 8 iPhone 6 iPhone X iPhone 13 Pro Max iPhone 12 Pro Max iPad Air 2 iOS15.5 beta4 iPhone 6 iPad mini 4 iPad Pro 11 2018 iPad Pro 12.9 2015 iPhone XR iPhone XS iPhone XR iPhone 7 iPad Pro 12.9 2017 iPhone 8 iPhone 6S iPad Pro 12.9 2017 iPad Pro 12.9 iPhone X iPhone 8 Plus iPad Air 3 (2019) iPhone 8 iPhone 12 Pro Max iPad Pro 12.9 2015 iPad mini 4 iPhone 13 mini iPad Air 2 iPhone 13 Pro iPhone 7 iPhone XS iPad 10.2 2021 9th Gen iPhone SE 2020 iPod Touch 7 iPad Air 2 iPhone 7 Plus iPhone SE 2022 iPhone 6S Plus iPhone 12'; 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