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

/
/
gm

Test String

Substitution

Processing...

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)Buy (\d+)\n(.*)\n(.*)\n(.*)\n(.*)\n").unwrap(); let string = "Buy 1 0.00161 19154259 30,804.1039267 30,804.1039267 Buy 2 0.00160 97058393 155,186.3181385 185,990.4220652 Buy 3 0.00159 41122703 65,279.2931204 251,269.7151856 Buy 4 0.00158 31934551 50,475.4559003 301,745.1710859 Buy 5 0.00157 3782692 5,943.6673093 307,688.8383952 Buy 6 0.00156 5976697 9,320.1865524 317,009.0249476 Buy 7 0.00155 22736745 35,230.3934790 352,239.4184266 Buy 8 0.00154 5347609 8,229.5362030 360,468.9546296 Buy 9 0.00153 3464283 5,302.3830325 365,771.3376621 Buy 10 0.00152 10692626 16,254.0610616 382,025.3987237 Buy 11 0.00151 17949230 27,091.3961166 409,116.7948403 Buy 12 0.00150 97614260 146,428.5035816 555,545.2984219 Buy 13 0.00149 2933085 4,367.6528087 559,912.9512306 Buy 14 0.00148 13280054 19,658.5822936 579,571.5335242 Buy 15 0.00147 5316367 7,816.6889988 587,388.2225230 Buy 16 0.00146 7788926 11,379.8559960 598,768.0785190 Buy 17 0.00145 19939233 28,951.3105372 627,719.3890562 Buy 18 0.00144 9125471 13,169.1109613 640,888.5000175 Buy 19 0.00143 15047419 21,528.2223294 662,416.7223469 Buy 20 0.00142 14442405 20,518.9900239 682,935.7123708 Buy 21 0.00141 7762618 10,954.5052212 693,890.2175920 Buy 22 0.00140 70712964 98,999.5705300 792,889.7881220 Buy 23 0.00139 18989941 26,429.5799747 819,319.3680967 Buy 24 0.00138 18402966 25,394.9657933 844,714.3338900 Buy 25 0.00137 6803275 9,332.4113272 854,046.7452172 Buy 26 0.00136 2160895 2,936.0797162 856,982.8249334 Buy 27 0.00135 32064580 43,285.0255160 900,267.8504494 Buy 28 0.00134 2160968 2,894.4177658 903,162.2682152 Buy 29 0.00133 16977334 22,584.7981210 925,747.0663362 Buy 30 0.00132 7917567 10,460.8080263 936,207.8743625 Buy 31 0.00131 12171178 15,930.0535734 952,137.9279359 Buy 32 0.00130 123592864 160,671.1593414 1,112,809.0872773 Buy 33 0.00129 42532906 54,830.3889145 1,167,639.4761918 Buy 34 0.00128 38688827 49,483.3175230 1,217,122.7937148 Buy 35 0.00127 1037481 1,318.9040123 1,218,441.6977271 Buy 36 0.00123 239488 293.6841344 1,218,735.3818615 Buy 37 0.00121 100000 121.3000000 1,218,856.6818615 Buy 38 0.00118 33819 40.0011132 1,218,896.6829747 Buy 39 0.00110 14330049 15,763.0539000 1,234,659.7368747 Buy 40 0.00098 507435 497.2863000 1,235,157.0231747 Buy 41 0.00081 16221 13.1665857 1,235,170.1897604 Buy 42 0.00060 5360817 3,216.4902000 1,238,386.6799604 "; let substitution = "Buy $1\\t$2\\t$3\\t$4\\t$5\\t\\n"; // result will be a String with the substituted value let result = regex.replace_all(string, substitution); println!("{}", result); }

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/