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

/
/
g

Test String

Code Generator

Generated Code

$re = '/([^\.!\?|\{\}]+[\.!\?]+(?:[a-z]+[\.!\?]+)?)/'; $str = '<h3>{h3A1 | h3B1 | h3C1 | h3D1 | h3E1 | h3F1 }</h3> {<h5>{h5A|h5B|h5C|h5D|h5E}</h5>|} <p>{ {pA1. |pB1. } {pC1. |pD1. } {pE1. |pF1. } | {ppA2. |ppB2. } {ppC2. |ppD2. } {ppE2.|ppF2. } }</p> {<h5>{A|B|C|D|E}</h5>|} <p>{{A. |B. } {C. |D. } {E. |F. }|{A. |B. } {C. |D.} {E. |F. }}</p> {<h5>{Getting the Best Google Maps Driving Directions | A History of Google Maps Driving Directions Refuted | The War Against Google Maps Driving Directions | If You Read Nothing Else Today, Read This Report on Google Maps Driving Directions | Facts, Fiction and Google Maps Driving Directions | What\'s Really Happening with Google Maps Driving Directions}</h5>|} <p>{{Whenever you would like to travel, the greatest worry is to receive the place quickly with the finest route. |It is a very major world and it\'s also quite easy to get lost in it if you really do not have precise directions on where you\'re going. } {When you\'re going to a certain address, you\'ll need to get an elaborated map of that particular location so you are able for exact and dependable directions to navigate your journey with nominal problems. |You might also want to search the country of Japan to choose where you want to see, just by typing in \'Japan\'. } {You can chose directions predicated on travel time or travel distance along with the web site will calculate a number of different routes if you\'re not happy with the initial one provided. |Not to worry, I\'ve developed an application that may be placed on nearly every site and generate a map and driving directions. }|{Gone are the times when you really need to hold a map in your hand to understand where you\'re going. |This is really a subject that everybody should know something about and within this article you\'ll be able to find out a number of the simple details you may need.} {This may save you quite a modicum of time in the event you frequently are looking up driving directions. |If you save that link for a bookmark or inside a Word document, then you are going to have the ability to access exactly the same group of directions for next time.} {If you\'re not close to the phone or have a voicemail system, you need to select postcard verification. |You\'re able to get to your own destination stress free, and truly feel great.}}</p> <p>{Now say you\'re in the auto driving but do not have any idea exactly where you are. |I like the simple to read instructions. } {It even lets you know how far it is to the following turn. |Hence you might lose out on brand new, short, alternate paths. } {Unfortunately there\'s not a established answer for this particular question. |Ergo, just since you might need to have a few detours on the way, so you could need to change your life roadmap from now and then. } {Don\'t forget, though, your fellow won\'t have a memory of the tiny incident. |This is helpful to recognize whenever you\'re approaching turns or exits and gives a major advantage on a standard map such as the ones you will discover with MapQuest.com. } {We\'re presented with detailed directions and possibly even pictures to create the trip as painless as possible. |But however this might not be the least path. }</p>'; 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