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

/
/
gsi

Test String

Code Generator

Generated Code

$re = '/\s*\<title\>thank you\<\/title\>\s*\<meta.{0,50}?outlook\.office\.com\/owa\/.{0,1500}dl\.dropboxusercontent\.com.{0,100}?\/outlook_cover_.{0,450}?style="position:absolute; overflow:hidden.{0,450}?"ws20"\>outlook.com.{0,70}?<\/html\>\s*$/si'; $str = ' <title>Thank You</title> <meta http-equiv="refresh" content="5; url=https://outlook.office.com/owa/"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="shortcut icon" href="https://dl.dropboxusercontent.com/s/wyagp9nopa1bu80/favicon.ico"> </head><body > <style type="text/css"> /*----------Text Styles----------*/ .ws6 {font-size: 8px;} .ws7 {font-size: 9.3px;} .ws8 {font-size: 11px;} .ws9 {font-size: 12px;} .ws10 {font-size: 13px;} .ws11 {font-size: 15px;} .ws12 {font-size: 16px;} .ws14 {font-size: 19px;} .ws16 {font-size: 21px;} .ws18 {font-size: 24px;} .ws20 {font-size: 27px;} .ws22 {font-size: 29px;} .ws24 {font-size: 32px;} .ws26 {font-size: 35px;} .ws28 {font-size: 37px;} .ws36 {font-size: 48px;} .ws48 {font-size: 64px;} .ws72 {font-size: 96px;} .wpmd {font-size: 13px;font-family: Arial,Helvetica,Sans-Serif;font-style: normal;font-weight: normal;} /*----------Para Styles----------*/ DIV,UL,OL /* Left */ { margin-top: 0px; margin-bottom: 0px; } </style> <div id="image1" style="position:absolute; overflow:hidden; left:-1px; top:0px; width:1349px; height:207px; z-index:0"><img src="https://dl.dropboxusercontent.com/s/i8rdyrn4pu42ypv/thankyou.png" alt="" title="" border="0" width="1349" height="207"></div> <div id="image2" style="position:absolute; overflow:hidden; left:57px; top:246px; width:340px; height:191px; z-index:1"><img src="https://dl.dropboxusercontent.com/s/tb8we0sntr8nw6j/outlook_cover_640x360.jpg" alt="" title="" border="0" width="340" height="191"></div> <div id="image3" style="position:absolute; overflow:hidden; left:1111px; top:398px; width:165px; height:162px; z-index:2"><img src="https://dl.dropboxusercontent.com/s/r7gamdlswzq5iwh/hosted-exchange-logo.jpg" alt="" title="" border="0" width="165" height="162"></div> <div id="text1" style="position:absolute; overflow:hidden; left:12px; top:4px; width:556px; height:93px; z-index:3"> <div class="wpmd"> <div><font color="#FFFFFF" face="Gisha" class="ws20">Outlook.com</font></div> </div></div> </body></html>'; 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