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)\e\[([0-9;]*)m").unwrap(); let string = "watson -c8 WATSON Loaded es7s/commons U+0 \\0 │ U+10 DLEU+20  SPU+30  0 U+40  @ U+50  P U+60  ` U+70  p  U+1 SOHU+11 DC1U+21  ! U+31  1 U+41  A U+51  Q U+61  a U+71  q  U+2 STXU+12 DC2U+22  \" U+32  2 U+42  B U+52  R U+62  b U+72  r  U+3 ETXU+13 DC3U+23  # U+33  3 U+43  C U+53  S U+63  c U+73  s  U+4 EOTU+14 DC4U+24  $ U+34  4 U+44  D U+54  T U+64  d U+74  t  U+5 ENQU+15 NAKU+25  % U+35  5 U+45  E U+55  U U+65  e U+75  u  U+6 ACKU+16 SYNU+26  & U+36  6 U+46  F U+56  V U+66  f U+76  v  U+7 \\aU+17 ETBU+27  ' U+37  7 U+47  G U+57  W U+67  g U+77  w  U+8 \\bU+18 CANU+28  ( U+38  8 U+48  H U+58  X U+68  h U+78  x  U+9 \\tU+19 EMU+29  ) U+39  9 U+49  I U+59  Y U+69  i U+79  y  U+A \\nU+1A SUBU+2A  * U+3A  : U+4A  J U+5A  Z U+6A  j U+7A  z  U+B \\vU+1B ESCU+2B  + U+3B  ; U+4B  K U+5B  [ U+6B  k U+7B  {  U+C \\fU+1C FSU+2C  , U+3C  < U+4C  L U+5C  \\ U+6C  l U+7C  |  U+D \\rU+1D GSU+2D  - U+3D  = U+4D  M U+5D  ] U+6D  m U+7D  }  U+E SOU+1E RSU+2E  . U+3E  > U+4E  N U+5E  ^ U+6E  n U+7E  ~  U+F SIU+1F USU+2F  / U+3F  ? U+4F  O U+5F  _ U+6F  o U+7F DEL │  "; // 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/