Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

/
/
xig

Test String

Code Generator

Generated Code

$re = '/(?={)(?(DEFINE) (?<number> [0-9]+(?:\.[0-9]*)?(?:e[+-]?[0-9]+)?) (?<string> \\\\" (?>[^"\\\\]+|\\\\\\\\(?:[^\\\\]|\\\\.))* \\\\" ) (?<boolean> true | false | null) (?<pair> (?: \g<string> | \g<number>) \s* : \s* (?: \g<string> | \g<number> | \g<boolean> | \g<json> | \g<array> ) ) (?<array> \[\s* \g<json> (?: \s*,\s* \g<json>)* \s*]) (?<json> { \s* \g<pair> (?:\s*,\s* \g<pair>)* }) ) \g<json>/xi'; $str = '"b<---------------->{\\"status\\":\\"ok\\",\\"plugin_version\\":\\"1.2.6\\",\\"post\\":{\\"id\\":7598,\\"type\\":\\"post\\",\\"slug\\":\\"honeycrisp-apple-sangria-recipe\\",\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-recipe\\\\/\\",\\"status\\":\\"publish\\",\\"title\\":\\"Honeycrisp Apple Sangria Recipe\\",\\"title_plain\\":\\"Honeycrisp Apple Sangria Recipe\\",\\"content\\":\\"<div class=\\\\\\"pin-it-btn-wrapper\\\\\\"><a href=\\\\\\"\\\\/\\\\/www.pinterest.com\\\\/pin\\\\/create\\\\/button\\\\/?url=http%3A%2F%2Fwww.bigbigbutts.com%2F2013%2F08%2Fhoneycrisp-apple-sangria-recipe%2F&media=http%3A%2F%2Fwww.bigbigbutts.com%2Fwp-content%2Fuploads%2F2013%2F08%2Fhoneycrisp-apple-sangria.jpg&description=Honeycrisp%20Apple%20Sangria%20Recipe\\\\\\" data-pin-do=\\\\\\"buttonBookmark\\\\\\" data-pin-config=\\\\\\"none\\\\\\" rel=\\\\\\"nobox\\\\\\"><\\\\/a><\\\\/div>\\",\\"raw_content\\":\\"\\",\\"excerpt\\":\\"\\",\\"date\\":\\"2013-08-24T11:18:07+00:00\\",\\"modified\\":\\"2014-04-24T09:45:00+00:00\\",\\"author\\":{\\"id\\":2,\\"slug\\":\\"gia\\",\\"name\\":\\"gia\\",\\"first_name\\":\\"gia\\",\\"last_name\\":\\"Wenner chia\\",\\"nickname\\":\\"gia\\",\\"url\\":\\"http:\\\\/\\\\/giawennerchia.com\\",\\"description\\":\\"gia Wenner chia is a writer and mom who gets paid to obsess over Pinterest and blogs for Ahalogy, a Cincinnati-based startup. She lives in her hometown of West Chester, Ohio, with her husband, two young children, and their dog.\\"},\\"attachments\\":[{\\"id\\":7599,\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria.jpg\\",\\"slug\\":\\"honeycrisp-apple-sangria\\",\\"title\\":\\"honeycrisp-apple-sangria\\",\\"description\\":\\"\\",\\"caption\\":\\"\\",\\"parent\\":7598,\\"mime_type\\":\\"image\\\\/jpeg\\",\\"images\\":{\\"full\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria.jpg\\",\\"width\\":580,\\"height\\":406},\\"thumbnail\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-150x150.jpg\\",\\"width\\":150,\\"height\\":150},\\"medium\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-300x210.jpg\\",\\"width\\":300,\\"height\\":210},\\"large\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria.jpg\\",\\"width\\":580,\\"height\\":406},\\"Mini Square\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-70x70.jpg\\",\\"width\\":70,\\"height\\":70},\\"Square\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-115x115.jpg\\",\\"width\\":115,\\"height\\":115},\\"Featured Tabs\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-150x225.jpg\\",\\"width\\":150,\\"height\\":225}}}],\\"featured_image\\":{\\"id\\":7599,\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria.jpg\\",\\"slug\\":\\"honeycrisp-apple-sangria\\",\\"title\\":\\"honeycrisp-apple-sangria\\",\\"description\\":\\"\\",\\"caption\\":\\"\\",\\"parent\\":7598,\\"mime_type\\":\\"image\\\\/jpeg\\",\\"images\\":{\\"full\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria.jpg\\",\\"width\\":580,\\"height\\":406},\\"thumbnail\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-150x150.jpg\\",\\"width\\":150,\\"height\\":150},\\"medium\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-300x210.jpg\\",\\"width\\":300,\\"height\\":210},\\"large\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria.jpg\\",\\"width\\":580,\\"height\\":406},\\"Mini Square\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-70x70.jpg\\",\\"width\\":70,\\"height\\":70},\\"Square\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-115x115.jpg\\",\\"width\\":115,\\"height\\":115},\\"Featured Tabs\\":{\\"url\\":\\"http:\\\\/\\\\/www.bigbigbutts.com\\\\/wp-content\\\\/uploads\\\\/2013\\\\/08\\\\/honeycrisp-apple-sangria-150x225.jpg\\",\\"width\\":150,\\"height\\":225}}}}}<random shit><dafkdjkfjdaksf"'; 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