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)([0-9]+)\s+([-.a-zA-Z0-9]+)\s+(\(([-.a-zA-Z0-9]+)\))?(.*)$").unwrap(); let string = " 1 10.110.255.129 42.759 ms 42.721 ms 42.718 ms 2 10.24.171.1 48.262 ms 48.628 ms 48.626 ms 3 10.110.255.186 43.377 ms 43.588 ms 43.602 ms 4 10.251.5.234 44.628 ms 44.625 ms 44.620 ms 5 10.251.5.162 163.039 ms 163.590 ms 163.581 ms 6 10.251.5.153 160.607 ms 157.800 ms 158.146 ms 7 10.3.63.132 181.292 ms 181.304 ms 181.171 ms 8 10.3.63.162 158.832 ms 162.948 ms 162.924 ms 9 10.3.64.239 156.895 ms 155.873 ms 156.368 ms 1 10.110.255.129 (10.110.255.129) 46.122 ms 46.160 ms 46.155 ms 2 jira1.cos.git.jdsu.net (10.24.171.1) 49.325 ms 49.308 ms 49.289 ms 3 10.110.255.186 (10.110.255.186) 47.280 ms 47.263 ms 47.245 ms 4 10.251.5.234 (10.251.5.234) 49.201 ms 49.184 ms 49.169 ms 5 10.251.5.162 (10.251.5.162) 181.687 ms 181.928 ms 181.910 ms 6 10.251.5.153 (10.251.5.153) 176.666 ms 169.844 ms 171.617 ms 7 10.3.63.132 (10.3.63.132) 172.793 ms 174.712 ms 174.690 ms 8 10.3.63.162 (10.3.63.162) 186.754 ms 187.607 ms 187.592 ms 9 10.3.64.239 (10.3.64.239) 173.878 ms 175.426 ms 175.500 ms magic scenarios: :D (be hostname) 1 91.121.19.253 1.349 ms 1.343 ms 1.862 ms 2 37.187.231.105 0.649 ms 0.602 ms 37.187.231.95 0.739 ms 3 37.187.232.88 12.179 ms 37.187.232.96 12.365 ms 12.424 ms 4 80.81.194.118 42.681 ms 42.771 ms 42.915 ms 5 213.252.224.238 43.622 ms 43.458 ms 43.479 ms 6 84.15.6.230 43.573 ms 84.15.6.226 43.323 ms 213.226.129.50 40.188 ms 7 141.136.40.34 40.250 ms 213.226.129.50 40.059 ms 40.051 ms magic scenarios: :D (su hostname) 1 rbx1-3b-a9.fr.eu (91.121.19.253) 1.648 ms 3.061 ms 3.220 ms 2 be11-315.rbx-g2-a9.fr.eu (37.187.231.107) 0.763 ms be11-315.rbx-g1-a9.fr.eu (37.187.231.105) 0.821 ms be11-146.rbx-g2-a9.fr.eu (37.187.231.97) 1.300 ms 3 be100-1120.fra-5-a9.de.eu (37.187.232.96) 12.250 ms be100-1105.fra-1-a9.de.eu (37.187.232.88) 12.354 ms be100-1120.fra-5-a9.de.eu (37.187.232.96) 12.293 ms 4 r2223.bee.lt (80.81.194.118) 42.643 ms 42.734 ms 42.870 ms 5 213.252.224.238 (213.252.224.238) 43.368 ms 43.399 ms 84.15.6.226 (84.15.6.226) 43.676 ms 6 84.15.6.226 (84.15.6.226) 43.460 ms 213.226.129.50 (213.226.129.50) 40.203 ms 84.15.6.226 (84.15.6.226) 43.329 ms 7 s1v3.e-lietuva.lt (141.136.40.34) 40.225 ms 213.226.129.50 (213.226.129.50) 40.106 ms 40.082 ms 1 rbx1-3b-a9.fr.eu (91.121.19.253) 1.648 ms 3.061 ms 3.220 ms 2 be11-315.rbx-g2-a9.fr.eu (37.187.231.107) 0.763 ms 2 be11-315.rbx-g1-a9.fr.eu (37.187.231.105) 0.821 ms 2 be11-146.rbx-g2-a9.fr.eu (37.187.231.97) 1.300 ms 3 be100-1120.fra-5-a9.de.eu (37.187.232.96) 12.250 ms 3 be100-1105.fra-1-a9.de.eu (37.187.232.88) 12.354 ms 3 be100-1120.fra-5-a9.de.eu (37.187.232.96) 12.293 ms 4 r2223.bee.lt (80.81.194.118) 42.643 ms 42.734 ms 42.870 ms 5 213.252.224.238 (213.252.224.238) 43.368 ms 43.399 ms 5 84.15.6.226 (84.15.6.226) 43.676 ms 6 84.15.6.226 (84.15.6.226) 43.460 ms 6 213.226.129.50 (213.226.129.50) 40.203 ms 6 84.15.6.226 (84.15.6.226) 43.329 ms 7 s1v3.e-lietuva.lt (141.136.40.34) 40.225 ms 7 213.226.129.50 (213.226.129.50) 40.106 ms 40.082 ms"; // 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/