Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

/
/
s

Test String

Substitution

Processing...

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"M220 S100 ;Reset Feedrate"; string substitution = @"M220 S80 ;Reset Feedrate"; string input = @";FLAVOR:Marlin ;TIME:61888 ;Filament used: 161.602m ;Layer height: 0.26 ;MINX:5.123 ;MINY:7.763 ;MINZ:0.3 ;MAXX:294.329 ;MAXY:283.097 ;MAXZ:98.66 ;Generated with Cura_SteamEngine 4.11.0 M140 S60 M105 M190 S60 M104 S195 M105 M109 S195 M82 ;absolute extrusion mode M201 X500.00 Y500.00 Z1000.00 E5000.00 ;Setup machine max acceleration M203 X500.00 Y500.00 Z12.00 E120.00 ;Setup machine max feedrate M204 P1250.00 R2250.00 T1250.00 ;Setup Print/Retract/Travel acceleration M205 X10.00 Y10.00 Z0.40 E2.50 ;Setup Jerk M220 S100 ;Reset Feedrate M221 S100 ;Reset Flowrate G28 ; home all axes M117 Purge extruder G92 E0 ; reset extruder G1 Z1.0 F3000 ; move z up little to prevent scratching of surface G1 X2 Y20 Z0.3 F5000.0 ; move to start-line position G1 X2 Y200.0 Z0.3 F1500.0 E15 ; draw 1st line G1 X2 Y200.0 Z0.4 F5000.0 ; move to side a little G1 X2 Y20 Z0.4 F1500.0 E30 ; draw 2nd line G92 E0 ; reset extruder G1 Z1.0 F3000 ; move z up little to prevent scratching of surface G92 E0 G92 E0 G1 F2400 E-1.5 ;LAYER_COUNT:377 ;LAYER:0 M107 G1 F600 Z0.9 ;MESH:E.stl G0 F7200 X183.805 Y131.583 Z0.9 ;TYPE:WALL-OUTER G1 F600 Z0.3 G1 F2400 E0.24945 G1 F1200 X183.805 Y134.317 E0.65456 G1 X189.081 Y134.317 E1.43632 G1 X189.081 Y135.404 E1.59739 G1 X184.172 Y135.404 E2.32477 G1 X184.172 Y138.131 E2.72884 G1 X189.081 Y138.131 E3.45623 G1 X189.081 Y139.712 E3.69049 G1 X183.618 Y139.712 E4.49997 G1 X183.618 Y142.44 E4.90419 G1 X192.135 Y142.44 E6.16618 G1 X192.135 Y131.583 E7.77491 G1 X184.113 Y131.583 E8.96356 G0 F600 X183.805 Y131.583 G0 F7200 X183.805 Y132.583 G0 X182.617 Y132.583 G1 F2400 E7.46356 G1 F600 Z0.9 G0 F7200 X187.241 Y124.597 Z0.9 G1 F600 Z0.3 G1 F2400 E9.21301 G1 F1200 X186.584 Y124.662 E9.31083 G1 X185.952 Y124.854 E9.40871 G1 X185.37 Y125.165 E9.50648 G1 X184.86 Y125.586 E9.60447 G1 X184.441 Y126.095 E9.70216 G1 X184.13 Y126.678 E9.80007 G1 X183.938 Y127.309 E9.8978 G1 X183.874 Y127.968 E9.99591 G1 X183.938 Y128.625 E10.09372 G1 X184.13 Y129.256 E10.19145 G1 X184.442 Y129.84 E10.28956 G1 X184.86 Y130.349 E10.38715 G1 X185.372 Y130.768 E10.48518 G1 X185.954 Y131.079 E10.58296 G1 X186.586 Y131.271 E10.68083 G1 X187.243 Y131.336 E10.77865 G1 X187.9 Y131.271 E10.87648 G1 X188.532 Y131.079 E10.97435 G1 X189.116 Y130.767 E11.07246 G1 X189.625 Y130.347 E11.17024 G1 X190.044 Y129.838 E11.26793 G1 X190.355 Y129.255 E11.36584 G1 X190.547 Y128.624 E11.46357 G1 X190.612 Y127.965 E11.56169 G1 X190.547 Y127.309 E11.65937 G1 X190.355 Y126.677 E11.75724 G1 X190.044 Y126.094 E11.85515 G1 X189.624 Y125.583 E11.95316 G1 X189.114 Y125.165 E12.05086 G1 X188.53 Y124.854 E12.1489 G1 X187.899 Y124.662 E12.24663 G1 X187.547 Y124.627 E12.29905 G0 F600 X187.241 Y124.597 G0 F7200 X186.584 Y124.662 G0 X186.259 Y124.76 G0 X185.915 Y123.623"; RegexOptions options = RegexOptions.Singleline; Regex regex = new Regex(pattern, options); string result = regex.Replace(input, substitution, 1); } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx