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"
"
gm

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#"(?m)nowrap=\"nowrap\" align=\"center.+?>(.+?)<\/td.+\n.+?align=\"right\"><a href=\"/.+?\/\">(.+?)<\/a>.+\n.+\n.+?href=\"\/teams\/.+?\">(.+?)<\/a>"#).unwrap(); let string = " <tr> <td class=\"hell\" nowrap=\"nowrap\" align=\"center\">01:00</td> <td class=\"hell\" align=\"right\"><a href=\"/teams/bayern-muenchen/\">Bayern München</a></td> <td class=\"hell\" align=\"center\"> - </td> <td class=\"hell\"><a href=\"/teams/real-madrid/\">Real Madrid</a></td> <td class=\"hell\" align=\"center\" nowrap> <a href=\"/report/freundschaft-vereine-2019-kalenderwoche-bayern-muenchen-real-madrid/\" title=\"Match details Bayern München - Real Madrid\">3:1 (1:0) </a> </td> <td class=\"hell\" align=\"center\"> </td> </tr> <tr> <td class=\"dunkel\" nowrap=\"nowrap\" align=\"center\">12:30</td> <td class=\"dunkel\" align=\"right\"><a href=\"/teams/juventus/\">Juventus</a></td> <td class=\"dunkel\" align=\"center\"> - </td> <td class=\"dunkel\"><a href=\"/teams/tottenham-hotspur/\">Tottenham Hotspur</a></td> <td class=\"dunkel\" align=\"center\" nowrap> -:- </td> <td class=\"dunkel\" align=\"center\"> <img src=\"https://s.hs-data.com/bilder/shared/live/4.png\"> </td> </tr> <tr> <td class=\"hell\" nowrap=\"nowrap\" align=\"center\">13:00</td> <td class=\"hell\" align=\"right\"><a href=\"/teams/gillingham-fc/\">Gillingham FC</a></td> <td class=\"hell\" align=\"center\"> - </td> <td class=\"hell\"><a href=\"/teams/millwall-fc/\">Millwall FC</a></td> <td class=\"hell\" align=\"center\" nowrap> -:- </td> <td class=\"hell\" align=\"center\"> <img src=\"https://s.hs-data.com/bilder/shared/live/4.png\"> </td> </tr> <tr> <td class=\"dunkel\" nowrap=\"nowrap\" align=\"center\">13:00</td> <td class=\"dunkel\" align=\"right\"><a href=\"/teams/sv-lippstadt-08/\">SV Lippstadt 08</a></td> <td class=\"dunkel\" align=\"center\"> - </td> <td class=\"dunkel\"><a href=\"/teams/ksv-baunatal/\">KSV Baunatal</a></td> <td class=\"dunkel\" align=\"center\" nowrap> -:- </td> <td class=\"dunkel\" align=\"center\"> </td> </tr> <tr> <td class=\"hell\" nowrap=\"nowrap\" align=\"center\">13:00</td> <td class=\"hell\" align=\"right\"><a href=\"/teams/sportfreunde-lotte/\">Sportfreunde Lotte</a></td> <td class=\"hell\" align=\"center\"> - </td> <td class=\"hell\"><a href=\"/teams/werder-bremen-ii/\">Werder Bremen II</a></td> <td class=\"hell\" align=\"center\" nowrap> -:- </td> <td class=\"hell\" align=\"center\"> </td> </tr> <tr> <td class=\"dunkel\" nowrap=\"nowrap\" align=\"center\">13:30</td> <td class=\"dunkel\" align=\"right\"><a href=\"/teams/holstein-kiel/\">Holstein Kiel</a></td> <td class=\"dunkel\" align=\"center\"> - </td> <td class=\"dunkel\"><a href=\"/teams/sheffield-wednesday/\">Sheffield Wednesday</a></td> <td class=\"dunkel\" align=\"center\" nowrap> <a href=\"/report/freundschaft-vereine-2019-kalenderwoche-holstein-kiel-sheffield-wednesday/\" title=\" Holstein Kiel - Sheffield Wednesday\">-:- </a> </td> <td class=\"dunkel\" align=\"center\"> </td> </tr> <tr> <td class=\"hell\" nowrap=\"nowrap\" align=\"center\">14:00</td> <td class=\"hell\" align=\"right\"><a href=\"/teams/sc-verl/\">SC Verl</a></td> <td class=\"hell\" align=\"center\"> - </td> <td class=\"hell\"><a href=\"/teams/arminia-bielefeld/\">Arminia Bielefeld</a></td> <td class=\"hell\" align=\"center\" nowrap> <a href=\"/report/freundschaft-vereine-2019-kalenderwoche-sc-verl-arminia-bielefeld/\" title=\" SC Verl - Arminia Bielefeld\">-:- </a> </td> <td class=\"hell\" align=\"center\"> </td> </tr> <tr> <td class=\"dunkel\" nowrap=\"nowrap\" align=\"center\">14:00</td> <td class=\"dunkel\" align=\"right\"><a href=\"/teams/shrewsbury-town/\">Shrewsbury Town</a></td> <td class=\"dunkel\" align=\"center\"> - </td> <td class=\"dunkel\"><a href=\"/teams/aston-villa/\">Aston Villa</a></td> <td class=\"dunkel\" align=\"center\" nowrap> -:- </td> <td class=\"dunkel\" align=\"center\"> <img src=\"https://s.hs-data.com/bilder/shared/live/4.png\"> </td> </tr> <tr> <td class=\"hell\" nowrap=\"nowrap\" align=\"center\">14:00</td> <td class=\"hell\" align=\"right\"><a href=\"/teams/standard-liege/\">Standard Liège</a></td> <td class=\"hell\" align=\"center\"> - </td> <td class=\"hell\"><a href=\"/teams/ogc-nice/\">OGC Nice</a></td> <td class=\"hell\" align=\"center\" nowrap> -:- </td> <td class=\"hell\" align=\"center\"> <img src=\"https://s.hs-data.com/bilder/shared/live/4.png\"> </td> </tr> <tr> <td class=\"dunkel\" nowrap=\"nowrap\" align=\"center\">14:00</td> <td class=\"dunkel\" align=\"right\"><a href=\"/teams/sv-wehen-wiesbaden/\">SV Wehen Wiesbaden</a></td> <td class=\"dunkel\" align=\"center\"> - </td> <td class=\"dunkel\"><a href=\"/teams/boavista/\">Boavista</a></td> <td class=\"dunkel\" align=\"center\" nowrap> -:- </td> <td class=\"dunkel\" align=\"center\"> </td> </tr> <tr> <td class=\"hell\" nowrap=\"nowrap\" align=\"center\">15:00</td> <td class=\"hell\" align=\"right\"><a href=\"/teams/1-fsv-mainz-05/\">1. FSV Mainz 05</a></td> <td class=\"hell\" align=\"center\"> - </td> <td class=\"hell\"><a href=\"/teams/jahn-regensburg/\">Jahn Regensburg</a></td> <td class=\"hell\" align=\"center\" nowrap> -:- </td> <td class=\"hell\" align=\"center\"> <img src=\"https://s.hs-data.com/bilder/shared/live/4.png\"> </td> </tr> <tr> <td class=\"dunkel\" nowrap=\"nowrap\" align=\"center\">15:00</td> <td class=\"dunkel\" align=\"right\"><a href=\"/teams/rangers-fc/\">Rangers FC</a></td> <td class=\"dunkel\" align=\"center\"> - </td> <td class=\"dunkel\"><a href=\"/teams/blackburn-rovers/\">Blackburn Rovers</a></td> <td class=\"dunkel\" align=\"center\" nowrap> -:- </td> <td class=\"dunkel\" align=\"center\"> <img src=\"https://s.hs-data.com/bilder/shared/live/4.png\"> </td> </tr> <tr> <td class=\"hell\" nowrap=\"nowrap\" align=\"center\">15:00</td> <td class=\"hell\" align=\"right\"><a href=\"/teams/kvc-westerlo/\">KVC Westerlo</a></td> <td class=\"hell\" align=\"center\"> - </td> <td class=\"hell\"><a href=\"/teams/krc-genk/\">KRC Genk</a></td> <td class=\"hell\" align=\"center\" nowrap> -:- </td> <td class=\"hell\" align=\"center\"> </td> </tr> <tr> <td class=\"dunkel\" nowrap=\"nowrap\" align=\"center\">16:00</td> <td class=\"dunkel\" align=\"right\"><a href=\"/teams/atalanta/\">Atalanta</a></td> <td class=\"dunkel\" align=\"center\"> - </td> <td class=\"dunkel\"><a href=\"/teams/ac-renate/\">AC Renate</a></td> <td class=\"dunkel\" align=\"center\" nowrap> -:- </td> <td class=\"dunkel\" align=\"center\"> </td> </tr> <tr> <td class=\"hell\" nowrap=\"nowrap\" align=\"center\">16:00</td> <td class=\"hell\" align=\"right\"><a href=\"/teams/lazio-roma/\">Lazio Roma</a></td> <td class=\"hell\" align=\"center\"> - </td> <td class=\"hell\"><a href=\"/teams/unione-triestina/\">Unione Triestina</a></td> <td class=\"hell\" align=\"center\" nowrap> -:- </td> <td class=\"hell\" align=\"center\"> </td> </tr> <tr> <td class=\"dunkel\" nowrap=\"nowrap\" align=\"center\">16:00</td> <td class=\"dunkel\" align=\"right\"><a href=\"/teams/spal-2013-ferrara/\">SPAL 2013 Ferrara</a></td> <td class=\"dunkel\" align=\"center\"> - </td> <td class=\"dunkel\"><a href=\"/teams/pordenone-calcio/\">Pordenone Calcio</a></td> <td class=\"dunkel\" align=\"center\" nowrap> -:- </td> <td class=\"dunkel\" align=\"center\"> </td> </tr> "; // result will be an iterator over tuples containing the start and end indices for each match in the string let result = regex.captures_iter(string); for mat in result { println!("{:?}", mat); } }

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/