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
No Match

r"
"

Test String

Code Generator

Generated Code

// include the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r"<th(?:| | .*?)>\s*<a(?:| | .*?)>\s*([\d.]+)\s*</a>\s*</th>\s*<td(?:| | .*?)>\s*stable\s*</td>").unwrap(); let string = " <table cellpadding=\"2\" cellspacing=\"1\" style=\"width: 100%; border: 0px;\"> <tr style=\"background-color: #CCCCCC;\"> <th colspan=\"5\">Available Releases</th> </tr> <tr> <th valign=\"top\" bgcolor=\"#ffffff\">Version</th> <th valign=\"top\" bgcolor=\"#ffffff\">State</th> <th valign=\"top\" bgcolor=\"#ffffff\">Release Date</th> <th valign=\"top\" bgcolor=\"#ffffff\">Downloads</th> <th valign=\"top\" bgcolor=\"#ffffff\">&nbsp;</th> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/5.1.2\">5.1.2</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">stable</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2015-12-07</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-5.1.2.tgz\">apcu-5.1.2.tgz</a> (105.7kB)</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=5.1.2\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/4.0.10\">4.0.10</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">stable</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2015-12-07</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-4.0.10.tgz\">apcu-4.0.10.tgz</a> (116.5kB)&nbsp;&nbsp;<a href=\"/package/APCu/4.0.10/windows\"><img src=\"/gifs/windows-icon.png\" />DLL</a></td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=4.0.10\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/5.1.0\">5.1.0</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">beta</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2015-11-21</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-5.1.0.tgz\">apcu-5.1.0.tgz</a> (106.8kB)</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=5.1.0\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/4.0.8\">4.0.8</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">stable</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2015-11-20</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-4.0.8.tgz\">apcu-4.0.8.tgz</a> (116.3kB)&nbsp;&nbsp;<a href=\"/package/APCu/4.0.8/windows\"><img src=\"/gifs/windows-icon.png\" />DLL</a></td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=4.0.8\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/4.0.7\">4.0.7</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">beta</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2014-10-11</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-4.0.7.tgz\">apcu-4.0.7.tgz</a> (115.9kB)&nbsp;&nbsp;<a href=\"/package/APCu/4.0.7/windows\"><img src=\"/gifs/windows-icon.png\" />DLL</a></td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=4.0.7\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/4.0.6\">4.0.6</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">beta</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2014-06-12</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-4.0.6.tgz\">apcu-4.0.6.tgz</a> (116.9kB)&nbsp;&nbsp;<a href=\"/package/APCu/4.0.6/windows\"><img src=\"/gifs/windows-icon.png\" />DLL</a></td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=4.0.6\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/4.0.5\">4.0.5</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">beta</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2014-06-11</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-4.0.5.tgz\">apcu-4.0.5.tgz</a> (116.9kB)&nbsp;&nbsp;<a href=\"/package/APCu/4.0.5/windows\"><img src=\"/gifs/windows-icon.png\" />DLL</a></td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=4.0.5\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/4.0.4\">4.0.4</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">beta</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2014-03-01</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-4.0.4.tgz\">apcu-4.0.4.tgz</a> (116.9kB)&nbsp;&nbsp;<a href=\"/package/APCu/4.0.4/windows\"><img src=\"/gifs/windows-icon.png\" />DLL</a></td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=4.0.4\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/4.0.3\">4.0.3</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">beta</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2014-01-27</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-4.0.3.tgz\">apcu-4.0.3.tgz</a> (116.9kB)&nbsp;&nbsp;<a href=\"/package/APCu/4.0.3/windows\"><img src=\"/gifs/windows-icon.png\" />DLL</a></td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=4.0.3\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/4.0.2\">4.0.2</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">beta</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2013-09-14</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-4.0.2.tgz\">apcu-4.0.2.tgz</a> (117.5kB)&nbsp;&nbsp;<a href=\"/package/APCu/4.0.2/windows\"><img src=\"/gifs/windows-icon.png\" />DLL</a></td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=4.0.2\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/4.0.1\">4.0.1</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">beta</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2013-04-30</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-4.0.1.tgz\">apcu-4.0.1.tgz</a> (103.4kB)&nbsp;&nbsp;<a href=\"/package/APCu/4.0.1/windows\"><img src=\"/gifs/windows-icon.png\" />DLL</a></td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=4.0.1\">Changelog</a>]</small></td> </tr> <tr> <th valign=\"top\" bgcolor=\"#cccccc\"><a href=\"/package/APCu/4.0.0\">4.0.0</a></th> <td valign=\"top\" bgcolor=\"#e8e8e8\">beta</td> <td valign=\"top\" bgcolor=\"#e8e8e8\">2013-03-26</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><a href=\"/get/apcu-4.0.0.tgz\">apcu-4.0.0.tgz</a> (101.8kB)</td> <td valign=\"top\" bgcolor=\"#e8e8e8\"><small>[<a href=\"/package-changelog.php?package=APCu&release=4.0.0\">Changelog</a>]</small></td> </tr> </table>"; // result will be a tuple containing the start and end indices for the first match in the string let result = regex.captures(string); let (start, end) = match result { Some((s, e)) => (s, e), None => { // ... } }; println!("{}", &string[start, end]); }

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 Rust, please visit: https://docs.rs/regex/latest/regex/