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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/^(<\!\-\- wp:onecms\/recipe-time \{\"type\"\:\"cook\")\S(.*[a-z\:0-9\}\s])(\/\-\->)$/m'; $str = '<!-- wp:onecms/recipe-header {"dek":"\\u003cp\\u003eHungry for some \\u003ca href=\\u0022https://www.southernliving.com/recipes/old-fashioned-apple-pie\\u0022\\u003eapple pie\\u003c/a\\u003e? We are right there with you. Here\'s the recipe from the Whispering Canyon Café at Disney’s Wilderness Lodge—dessert will never be the same.\\u003c/p\\u003e"} /--> <!-- wp:onecms/primary-media /--> <!-- wp:onecms/recipe-media /--> <!-- wp:onecms/recipe-container --> <!-- wp:onecms/recipe-details --> <!-- wp:onecms/recipe-metadata {"yieldDescription":"Makes one 9-inch pie."} /--> <!-- wp:onecms/recipe-times --> <!-- wp:onecms/recipe-time {"type":"hands-on","days":0,"hours":0,"minutes":45} /--> <!-- wp:onecms/recipe-time {"type":"cook","days":0,"hours":1,"minutes":0} /--> <!-- /wp:onecms/recipe-times --> <!-- /wp:onecms/recipe-details --> <!-- wp:onecms/recipe-ingredients --> <!-- wp:onecms/recipe-section-header {"content":"Pie Crust"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"butter, cut into small pieces","customMeasure":"tablespoons","customQuantity":"4"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"shortening","customMeasure":"cup","customQuantity":"0.25"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"all-purpose flour","customMeasure":"cups","customQuantity":"1.75"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"sugar","customMeasure":"teaspoons","customQuantity":"4"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"coarse salt","customMeasure":"teaspoon","customQuantity":"0.13"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"2% milk","customMeasure":"cup","customQuantity":"0.33"} /--> <!-- wp:onecms/recipe-section-header {"content":"Apples"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"water","customMeasure":"cup","customQuantity":"1"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"Granny Smith apples, peeled and sliced","customQuantity":"6"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"apple pie spice","customMeasure":"teaspoon","customQuantity":"2"} /--> <!-- wp:onecms/recipe-section-header {"content":"Apple Pie Batter"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"butter, softened","customMeasure":"cup","customQuantity":"0.5"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"sugar","customMeasure":"cup","customQuantity":"0.67"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"eggs","customQuantity":"2"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"flour","customMeasure":"cups","customQuantity":"1.5"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"baking powder","customMeasure":"teaspoon","customQuantity":"1.5"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"salt","customMeasure":"teaspoon","customQuantity":"0.13"} /--> <!-- wp:onecms/recipe-ingredient-custom {"customIngredient":"heavy cream","customMeasure":"cup","customQuantity":"0.25"} /--> <!-- /wp:onecms/recipe-ingredients --> <!-- wp:onecms/recipe-nutrition {"displayNutritionRecipe":false} /--> <!-- wp:onecms/recipe-directions --> <!-- wp:onecms/recipe-direction {"directionId":"ddaa1eec-7bec-4284-b4e3-53b35cb83941","content":"\\u003cstrong\\u003eFOR PIE CRUST: \\u003c/strong\\u003e"} /--> <!-- wp:onecms/recipe-direction {"directionId":"e546e3c3-96a5-4be5-94fa-34ee625f3a48","content":"\\u003cstrong\\u003eFOR APPLES:\\u003c/strong\\u003e"} /--> <!-- wp:onecms/recipe-direction {"directionId":"49fbc0c6-12f0-420c-9dc6-19210620e023","content":"\\u003cstrong\\u003eFOR APPLE PIE BATTER:\\u003c/strong\\u003e"} /--> <!-- wp:onecms/recipe-direction {"directionId":"208717df-e3e3-43e9-a2bc-35ad854ae43c","content":"\\u003cstrong\\u003eFOR APPLE PIE:\\u003c/strong\\u003e"} /--> <!-- /wp:onecms/recipe-directions --> <!-- wp:onecms/recipe-notes --> <!-- wp:onecms/recipe-note /--> <!-- /wp:onecms/recipe-notes --> <!-- /wp:onecms/recipe-container -->'; 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