Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • Update Regex
    ctrl+⇧+s
  • Save new 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
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

@
@
siU

Test String

Code Generator

Generated Code

$re = '@(?:\[url=(?:&quot;|"|\'|)(?:(?:(?:(?:(?!https?|ftp|mailto).)*):(?://)?)(?:(?!"|"|&quote;).)++)(?:&quot;|"|\'|)\])(?:(?!\[/url\]).)++(?:\[/url\])@siU'; $str = '[url="snafu://xy.sf.net/cgi-bin/xidelcgi?&data=%3Ctable%20class%3D%22ClassGrid%22%20cellspacing%3D%220%22%20cellpadding%3D%220%22%20border%3D%220%22%20id%3D%22_ctl0_phMainContent_dgrdClasses%22%20style%3D%22border-collapse%3Acollapse%3B%22%3E%0A%3Ctbody%3E%0A%20%20%20%20%3Ctr%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow1%22%20colspan%3D%223%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Chr%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%3C%2Ftr%3E%0A%20%20%20%20%3Ctr%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow1%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox1%22%3EAddress%20123%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cbr%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cbr%3E%3Ca%20target%3D%22_blank%22%20class%3D%22gridDirections%22%20href%3D%22%2FClasses%2FDirections.aspx%23104%22%3EDirections%3C%2Fa%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow2%22%3E%0A%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox2%22%3E12%2F12%2F2018%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow3%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox3%22%3E%3Ca%20id%3D%22_ctl0_phMainContent_dgrdClasses__ctl3_hplAddToCart%22%20class%3D%22whitelight%22%20href%3D%22%2Fvalidate.aspx%3FClassID1%3D4233%26amp%3BClassID2%3D0%22%3EBook%20Now%3C%2Fa%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%3C%2Ftr%3E%0A%20%20%20%20%3Ctr%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow1%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox1%22%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow2%22%3E%0A%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox2%22%3E1%2F24%2F2019%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow3%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox3%22%3E%3Ca%20id%3D%22_ctl0_phMainContent_dgrdClasses__ctl4_hplAddToCart%22%20class%3D%22whitelight%22%20href%3D%22%2Fvalidate.aspx%3FClassID1%3D4306%26amp%3BClassID2%3D0%22%3EBook%20Now%3C%2Fa%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%3C%2Ftr%3E%0A%20%20%20%20%3Ctr%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow1%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox1%22%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow2%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox2%22%3ESaturday%2C%20August%204%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow3%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBoxNone%22%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%3C%2Ftr%3E%0A%20%20%20%20%3Ctr%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow1%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox1%22%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow2%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox2%22%3ESaturday%2C%20August%2018%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%20%20%20%20%3Ctd%20class%3D%22ClassGridRow3%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22ClassGridBox3%22%3E%3Ca%20id%3D%22_ctl0_phMainContent_dgrdClasses__ctl6_hplAddToCart%22%20class%3D%22whitelight%22%20href%3D%22%2Fvalidate.aspx%3FClassID1%3D4346%26amp%3BClassID2%3D0%22%3EBook%20Now%3C%2Fa%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Ftd%3E%0A%20%20%20%20%3C%2Ftr%3E%0A%3C%2Ftbody%3E&=&extract=%2F%2Ftbody%2Ftr%2Ftd%2Fdiv%5B%40class%3D%22ClassGridBox1%22%5D%2F%5Breplace(text()%2C\'(%5E%5Ba-zA-Z.-%5D%2B%20%5B0-9%5D%2B).*\'%2C\'%241\'%2C%20\'s\')%5D&=%2F%2Ftbody%2Ftr%2Ftd%2Fdiv%5B%40class%3D%22ClassGridBox1%22%5D%2F%5Breplace(text()%2C\'(%5E%5Ba-zA-Z.-%5D%2B%20%5B0-9%5D%2B).*\'%2C\'%241\'%2C%20\'s\')%5D&input-format=auto&printed-node-format=xml&output-format=adhoc&compatibility=Enable%20all%20extensions&dot-notation=unambiguous&extract-kind=xpath2&print-type-annotations=true"]example[/url]'; 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