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

Substitution

Processing...

Code Generator

Generated Code

$re = '~\@\w{40}.(js|css)~m'; $str = '/js/jquery.cycle.custom.min@48bbf3f9d2712e4e6d6b7b0ce1cc92cade858979.css /js/jquery.cycle.custom.min@48bbf3f9d2712e4e6d6b7b0ce1cc92cade858979.js http://128.1.10.202:9090/ec2/resources/styles/blueprint/src/reset@60ee89fe415ed91091b8e5b69667bcc111b559a2.css? appended=/styles/blueprint/screen@e8844fdaab6e412af57dfbfa4856cfa9d1d5124c.css,/styles/blueprint/typography@c4d37f15a78c5e05900e8a38d6fe0a7c932dc55c.css,/styles/blueprint/plugins/buttons/screen@2438b502b8bcaf5df6e5afa2a1081ddb1fbdd46a.css,/styles/jqzoom@6bf4516d76e9833c7d08690457667beaaf080e9a.css,/styles/style@6f5eb8c2081050071fc62e1cadac92f6bfded2b6.css,/styles/buttons@7ae2d029c26451327feec447e7f7eb1f78bdb9b9.css,/styles/style-standard@a373e18822d0e82ad287d4177eee6e83c0179cf5.css,/styles/messi/messi@7b50c7a29f6de29b9bbb78f10d9a853463ee45b2.css,/styles/modal-dialogs@c869667938f54304f727b08a599c74e3f02386c1.css,/colorbox/colorbox@1317faafe6a53060469798eac153882078a879a3.css,/styles/jquery.ui.spinner@a6c7fcd296725410f350aecaa5dd7c9f217f764f.css,/styles/ui/custom-theme/jquery-ui-1.8.20.custom@4bd57bf992a9cf092102acf958de146ad6fc392d.css,/styles/ui/custom-theme/jquery-ui-timepicker@b98d7a4ea7717d42aab28bb41bccdd706bfd7096.css'; $subst = ""; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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