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
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

/
/
gim

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/^\/ignition-interlock-device\/([a-z]*?)\/(locations)?\/smart-start-of-([a-z0-9-]*?)(\/)?$/im'; $str = '/ignition-interlock-device/colorado/locations/smart-start-of-alamosa/ /ignition-interlock-device/colorado/locations/smart-start-of-auburn-2/ /ignition-interlock-device/florida/locations/smart-start-of-beverly/ /ignition-interlock-device/florida/locations/smart-start-of-boca-raton-2/ /ignition-interlock-device/florida/locations/smart-start-of-brownsville/ /ignition-interlock-device/florida/locations/smart-start-of-camrose/ /ignition-interlock-device/florida/locations/smart-start-of-carbondale/ /ignition-interlock-device/florida/locations/smart-start-of-carson-city/ /ignition-interlock-device/florida/locations/smart-start-of-centereach/ /ignition-interlock-device/florida/locations/smart-start-of-charleston-2/ /ignition-interlock-device/florida/locations/smart-start-of-charleston/ /ignition-interlock-device/florida/locations/smart-start-of-danielson/ /ignition-interlock-device/florida/locations/smart-start-of-defuniak-springs/ /ignition-interlock-device/florida/locations/smart-start-of-deland-2/ /ignition-interlock-device/florida/locations/smart-start-of-durango/ /ignition-interlock-device/florida/locations/smart-start-of-farmington/ /ignition-interlock-device/florida/locations/smart-start-of-framingham/ /ignition-interlock-device/florida/locations/smart-start-of-gallatin/ /ignition-interlock-device/florida/locations/smart-start-of-gresham/ /ignition-interlock-device/florida/locations/smart-start-of-gypsum/ /ignition-interlock-device/florida/locations/smart-start-of-hialeah/ /ignition-interlock-device/florida/locations/smart-start-of-holly-hill-2/ /ignition-interlock-device/florida/locations/smart-start-of-honolulu-3/ /ignition-interlock-device/florida/locations/smart-start-of-huntington/ /ignition-interlock-device/florida/locations/smart-start-of-huntsville/ /ignition-interlock-device/florida/locations/smart-start-of-kennesaw/ /ignition-interlock-device/florida/locations/smart-start-of-kennewick/ /ignition-interlock-device/florida/locations/smart-start-of-kissimmee-2/ /ignition-interlock-device/florida/locations/smart-start-of-la-crosse/ /ignition-interlock-device/florida/locations/smart-start-of-laramie/ /ignition-interlock-device/florida/locations/smart-start-of-lawton/ /ignition-interlock-device/florida/locations/smart-start-of-longwood/ /ignition-interlock-device/florida/locations/smart-start-of-malden/ /ignition-interlock-device/florida/locations/smart-start-of-mckinney/ /ignition-interlock-device/florida/locations/smart-start-of-medford/ /ignition-interlock-device/florida/locations/smart-start-of-middletown-2/ /ignition-interlock-device/florida/locations/smart-start-of-middletown/ /ignition-interlock-device/florida/locations/smart-start-of-mildura/ /ignition-interlock-device/florida/locations/smart-start-of-new-port-richey/ /ignition-interlock-device/florida/locations/smart-start-of-norco/ /ignition-interlock-device/florida/locations/smart-start-of-ocala-2/ /ignition-interlock-device/florida/locations/smart-start-of-palm-bay-2/ /ignition-interlock-device/florida/locations/smart-start-of-palm-bay/ /ignition-interlock-device/florida/locations/smart-start-of-panama-city-2/ /ignition-interlock-device/florida/locations/smart-start-of-port-charlotte-2/ /ignition-interlock-device/florida/locations/smart-start-of-richmond-3/ /ignition-interlock-device/florida/locations/smart-start-of-saint-paul-2/ /ignition-interlock-device/florida/locations/smart-start-of-san-marcos/ /ignition-interlock-device/florida/locations/smart-start-of-santa-ana/ /ignition-interlock-device/florida/locations/smart-start-of-show-low/ /ignition-interlock-device/florida/locations/smart-start-of-staunton/ /ignition-interlock-device/florida/locations/smart-start-of-tallahassee-2/ /ignition-interlock-device/florida/locations/smart-start-of-titusville/ /ignition-interlock-device/florida/locations/smart-start-of-uppsala-2/ /ignition-interlock-device/florida/locations/smart-start-of-van-wert/ /ignition-interlock-device/florida/locations/smart-start-of-west-monroe/ /ignition-interlock-device/florida/locations/smart-start-of-west-palm-beach-2/'; $subst = "/locations/?location_redirect=$3&state=$1"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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