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

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