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

/
/

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"^.*250 g<\/td><td><span[^>]*>([0-9]+)\.([0-9]+[0-9]+[0-9]+)\,([0-9]+[0-9]+)<\/span>.*$").unwrap(); let string = " <div id=\"content\" class=\"s1\"><!--TYPO3SEARCH_begin--><div id=\"c27140\" class=\"csc-default\"><h1>Preise für Goldbarren, Silberbarren, Platinbarren und Palladiumbarren</h1><p class=\"bodytext\">Alle Ankauf-Preise in Euro. ESG-Schalterankaufspreise vom&nbsp;10.07.2015 / <span title=\"date-otc\">10.07.2015</span>.</p><table class=\"quotetable\"> <thead> <tr><th>Barren</th> <th scope=\"col\">Gold<br /><img src=\"fileadmin/_migrated/RTE/RTEmagicC_gold_small_02.png.png\" title=\"gold small\" txdam=\"1005\" height=\"52\" width=\"70\" alt=\"\" /></th> <th scope=\"col\">Silber<br /><img src=\"fileadmin/_migrated/RTE/RTEmagicC_silver_small_02.png.png\" title=\"silver small\" txdam=\"1008\" height=\"52\" width=\"70\" alt=\"\" /></th> <th scope=\"col\">Palladium<br /><img src=\"fileadmin/_migrated/RTE/RTEmagicC_palladium_small_02.png.png\" title=\"palladium small\" txdam=\"1006\" height=\"52\" width=\"70\" alt=\"\" /></th> <th scope=\"col\">Platin<br /><img src=\"fileadmin/_migrated/RTE/RTEmagicC_platinum_small_02.png.png\" title=\"platinum small\" txdam=\"1007\" height=\"52\" width=\"70\" alt=\"\" /></th> </tr> </thead> <tbody> <tr class=\"impair\"> <td class=\"th\">1 g</td><td><span title=\"01011011-otc\">33,43</span> €</td><td><span title=\"10201714-otc\">0,44</span> €</td><td><span title=\"10201762-otc\">17,90</span> €</td><td><span title=\"10201752-otc\">28,64</span> €</td></tr> <tr><td class=\"th\">5 g</td><td><span title=\"01011021-otc\">167,16</span> €</td><td><span title=\"10201715-otc\">2,22</span> €</td><td><span title=\"10201763-otc\">89,53</span> €</td><td><span title=\"10201753-otc\">143,22</span> €</td></tr> <tr class=\"impair\"><td class=\"th\">10 g</td><td><span title=\"01011031-otc\">334,33</span> €</td><td><span title=\"10201716-otc\">4,45</span> €</td><td><span title=\"10201764-otc\">179,06</span> €</td><td><span title=\"10201754-otc\">286,44</span> €</td></tr> <tr><td class=\"th\">20 g</td><td><span title=\"01011041-otc\">668,66</span> €</td><td><span title=\"10201720-otc\">8,91</span> €</td><td><span title=\"10201765-otc\">358,12</span> €</td><td><span title=\"10201755-otc\">572,88</span> €</td></tr> <tr class=\"impair\"><td class=\"th\"><p class=\"align-right\"><b>1 oz </b></p><p class=\"align-right\"><b>(31,10 g)<br /></b></p></td><td><b><span title=\"01011051-otc\">1.039,78</span> €<br /></b></td><td><b><span title=\"10201893-otc\">13,86</span> €<br /></b></td><td><b><span title=\"10201766-otc\">556,88</span> €<br /></b></td><td><b><span title=\"10201756-otc\">890,84</span> €<br /></b></td></tr> <tr><td class=\"th\">50 g</td><td><span title=\"01011061-otc\">1.671,67</span> €</td><td><span title=\"10201721-otc\">22,29</span> €</td><td><span title=\"10201767-otc\">895,31</span> € </td><td><span title=\"10201757-otc\">1.432,22</span> €</td></tr> <tr class=\"impair\"><td class=\"th\">100 g</td><td><span title=\"01011071-otc\">3.343,34</span> €</td><td><span title=\"10201722-otc\">44,59</span> €</td><td><span title=\"10201768-otc\">1.790,62</span> €</td><td><span title=\"10201758-otc\">2.864,44</span> €</td></tr> <tr><td class=\"th\">250 g</td><td><span title=\"01011081-otc\">8.358,36</span> €</td><td><span title=\"10201723-otc\">111,49</span> €</td><td><span title=\"10201769-otc\">4.476,55</span> €</td><td><span title=\"10201759-otc\">7.161,10</span> €</td></tr> <tr class=\"impair\"><td class=\"th\">500 g</td><td><span title=\"01011091-otc\">16.716,73</span> €</td><td><span title=\"10201724-otc\">222,99</span> €</td><td><span title=\"10201770-otc\">8.953,11</span> €</td><td><span title=\"10201760-otc\">14.322,21</span> €</td></tr> <tr><td class=\"th\">1000 g</td><td><span title=\"01011101-otc\">33.433,47</span> €</td><td><span title=\"10201725-otc\">445,98</span> €</td><td><span title=\"10201771-otc\">17.906,23</span> €</td><td><span title=\"10201761-otc\">28.644,42</span> €</td></tr></tbody></table><ul><li>1oz = 1 Unze = 31,10g</li><li>Maßgeblich für den Gutschriftsbetrag / Auszahlungsbetrag ist jeweils der Tageskurs bei Barreneingang in unserem Hause) </li></ul></div><div class=\"csc-default\"><div class=\"divider\"><hr /></div></div><div id=\"c12890\" class=\"csc-default\"><div class=\"yui-g\">"; // 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/