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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

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)(Send: (N\d+\s+)?(G0|G1|G2|G3)).*|(Recv: ok)").unwrap(); let string = "Send: N15316 G2 X132.005 Y144.699 I2.530 J2.266 E1967.48230*80 Recv: ok Send: N15317 G2 X130.872 Y146.440 I8.090 J6.504 E1967.55146*83 Recv: ok Send: N15318 G3 X128.033 Y150.765 I-83.048 J-51.420 E1967.72359*80 Recv: ok Send: N15319 G2 X126.450 Y152.896 I19.401 J16.065 E1967.81191*88 Recv: ok Send: N15320 G3 X123.581 Y158.450 I-52.577 J-23.641 E1968.01996*86 Recv: ok Send: N3830 G1 F1800 X137.124 Y134.295 E1247.73559*2 Recv: ok Send: N3831 G0 F7200 X137.525 Y134.131*112 Recv: ok Send: N3832 G1 F1800 X173.8 Y170.406 E1249.44186*15 Recv: ok Send: N3833 G0 F7200 X173.957 Y169.997*119 Recv: == T:209.96 /210.00 == B:60.21 /60.00 @:79 B@:127 Recv: ok Send: N3834 G1 F1800 X137.95 Y133.991 E1251.13549*53 Recv: ok Send: N3835 G0 F7200 X138.404 Y133.878*122 Recv: ok Send: N3836 G1 F1800 X174.132 Y169.606 E1252.81603*7 Recv: ok Send: N3837 G0 F7200 X174.242 Y169.151*121 Recv: == T:209.73 /210.00 == B:60.66 /60.00 @:85 B@:0 Recv: ok Send: N3838 G1 F1800 X138.857 Y133.766 E1254.48043*2 Recv: ok Send: N3839 G0 F7200 X139.311 Y133.654*116 Recv: == T:209.77 /210.00 == B:60.69 /60.00 @:84 B@:0 Recv: ok Send: N3840 G1 F1800 X174.354 Y168.697 E1256.12874*13 Recv: ok Send: N3841 G0 F7200 X174.465 Y168.242*123 Recv: ok Send: N3842 G1 F1800 X139.775 Y133.553 E1257.76043*11 Recv: ok Send: N3843 G0 F7200 X140.258 Y133.469*119 Recv: == T:209.92 /210.00 == B:60.65 /60.00 @:79 B@:0 Recv: ok "; // 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/