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)BCF-(\d+)\s+([\w]+)[A-Z\s\d\-]+(?:BTS-\d+[\sA-Z-]+\d+\s+\d+\s+)([A-Z]+)").unwrap(); let string = "BCF-1522 FLEXI EDGE U WO 4 B1522 WO 01137 22186 BTS-1522 U WO 1 0 CALLEORIN6 RF/- 23 TRX-001 U WO 673 0 1787 MBCCH P 10 TRX-002 U WO 681 0 1787 9 TRX-003 U WO 663 0 1787 8 TRX-004 U WO 659 0 1787 6 01137 22187 BTS-1523 U WO 0 1 CALLEORIN7 RF/- 24 TRX-005 U WO 675 0 320 MBCCH P 8 TRX-006 U WO 657 0 320 10 TRX-007 U WO 665 0 320 4 TRX-008 U WO 638 0 320 0 01137 22188 BTS-1524 U WO 0 0 CALLEORIN8 RF/- 16 TRX-009 U WO 651 0 1729 MBCCH P 7 TRX-010 U WO 643 0 1729 4 TRX-011 U WO 648 0 1729 7 BCF-1526 ULTRASITE U BL-BCF 7 B1526 WO 01134 01186 BTS-1526 U BL-BCF 0 0 LDANIELAS6 RF/- 0 EDGE TRX-001 U BL-BCF 672 0 1736 MBCCH P 2 EDGE TRX-002 U BL-BCF 674 0 1736 0 EDGE TRX-003 U BL-BCF 657 0 1737 5 EDGE TRX-004 U BL-BCF 648 0 1737 6 01134 01187 BTS-1527 U BL-BCF 0 0 LDANIELAS7 RF/- 0 EDGE TRX-005 U BL-BCF 645 0 1736 2 EDGE TRX-006 U BL-BCF 639 0 1736 0 EDGE TRX-007 U BL-BCF 683 0 1736 MBCCH P 5 EDGE TRX-008 U BL-BCF 641 0 1736 6 01134 01188 BTS-1528 U BL-BCF 0 0 LDANIELAS8 RF/- 0 EDGE TRX-009 U BL-BCF 662 0 1737 MBCCH P 7 EDGE TRX-010 U BL-BCF 643 0 1737 2 EDGE TRX-011 U BL-BCF 652 0 1737 0 EDGE TRX-012 U BL-BCF 664 0 1737 5 BCF-1540 ULTRASITE L BL-USR 3 B1540 BL 01134 12543 BTS-0055 L BL-USR 0 0 SANTAINES3 RF/- 0 EDGE TRX-001 U BL-USR 128 0 1773 MBCCH P 9 EDGE TRX-003 U BL-USR 145 0 1773 10 EDGE TRX-004 U BL-USR 237 0 1773 4 EDGE TRX-005 U BL-USR 155 0 1773 2 EDGE TRX-006 U BL-USR 233 0 1773 9 EDGE TRX-007 U BL-USR 150 0 1773 10 01134 12548 BTS-0057 L BL-USR 0 0 SANTAINES8 RF/- 0 EDGE TRX-008 U BL-USR 669 0 1361 MBCCH P 6 EDGE TRX-010 U BL-USR 643 0 1361 4 EDGE TRX-011 U BL-USR 683 0 1361 2 EDGE TRX-012 U BL-USR 664 0 1361 9 BCF-1543 ULTRASITE U WO 6 B1543 WO 01137 12822 BTS-0206 U WO 0 0 VERACRUZ2 RF/- 0 EDGE TRX-001 U WO 137 0 1771 MBCCH P 10 EDGE TRX-002 U BL-RSL 128 0 1771 8 EDGE TRX-003 U WO 139 0 1771 10 01137 12828 BTS-0717 U WO 1 0 VERACRUZ8 RF/- 8 EDGE TRX-005 U WO 678 0 1735 MBCCH P 0 EDGE TRX-007 U BL-RSL 655 0 1735 3 EDGE TRX-008 U WO 649 0 1735 6 EDGE TRX-009 U BL-RSL 657 0 1735 3 BCF-1615 ULTRASITE U WO 2 B1615 WO 01139 10012 BTS-0086 L BL-USR 0 0 ADRIATICA2 RF/- 0 EDGE TRX-001 U BL-USR 135 0 1366 MBCCH P 10 EDGE TRX-003 U BL-USR 133 0 1366 10 EDGE TRX-004 U BL-USR 147 0 1366 9 EDGE TRX-005 U BL-USR 153 0 1682 10 EDGE TRX-006 U BL-USR 155 0 1682 4 "; // 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/