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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "^(?P<operating_pressure>H)(?P<sep_1>-)(?P<number_of_main_ports>4)(?P<unit_type>W)(?P<actuation_type>EH|H)(?P<unit_size>82)(?P<spool_feedback_main_stage>H|)(?P<spool_symbol>C|D|K|Z|E|F|G|H|J|L|M|Q|R|S|T|U|V|W)(?P<unit_series>3X)(?P<mounting_type>F|)(?P<sep_2>/)(?P<spool_feedback>OF|O|)(?P<pilot_valve>10)(?P<type_of_solenoid>A|L)(?P<solenoid_in_ac_or_dc_version>G|W)(?P<voltage_of_solenoid>220|195|180|127|120|110|96|60|42|24|12)(?P<voltage_rectifier>R|-|)(?P<manual_override_unit>N|)(?P<spool_position_monitoring>Y|)(?P<control_volume_flow>)(?P<unit_for_time_adjustment>S2|S|)(?P<electrical_connection>Z5L|Z2L|Z1L|DKL|DZL|DL|DZ|DK|ZL|KL|Z5|Z4|Z2|Z1|D|L|Z|K|)(?P<sep_3>/)(?P<additional_equipment>17|16|15|14|13|12|11|10|)(?P<orifice_positon>B|)(?P<orifice_diameter>15|12|11|10|08|)(?P<pressure_reducing_valve>D1|)(?P<seal_material>V|)(?P<additional_details>)$\n"; final String string = "H-4WEH82HD3XF/10CG24N9SK4\n" + "H-4WEH82HE3X/10EG24N9SK4\n" + "H-4WEH82HG3XF/10CW110N9DAL/V\n" + "H-4WEH82HF3XF/10CG24N9S2K4\n" + "H-4WEH82HL3X/10CG24N9S2K4\n" + "H-4WEH82HG3XF/10CW230RNSDL/13\n" + "H-4WEH82HJ3XF/10CG24N9K4\n" + "H-4WEH82E3X/10CG24N9K4\n" + "H-4WEH82HG3XF/10EG24N9SK4/B12\n" + "H-4WEH82HM3XF/10CW110N9\n" + "H-4WEH82HJ3X/10CG24N9ETK4/B10D2\n" + "H-4WEH82HE3X/16AG24NSZ5LQ0G24SO38\n" + "H-4WEH82HE3XF/10CG24N9SDZ/13SO6\n" + "H-4WEH82HE3X/16AG24NZ5LSO8\n" + "H-4WEH82HC3X/10CG24N9S\n" + "H-4WEH82HE3X/10EG24N9K4\n" + "H-4WEH82E3X/10CG24N9SK4QMABG24\n" + "H-4WEH82HE3X/10CG24N9S2\n" + "H-4WEH82HC3X/10CW110N9S2DAL\n" + "H-4WEH82HM3XF/10CW110N9K4\n" + "H-4WEH82HE3XF/10CG60NS2DKL\n" + "H-4WEH82HE3XF/U\n" + "H-4WEH82HD3XF/10CG60NS2DKL\n" + "H-4WEH82HE3X/10CG24N9SK4\n" + "H-4WEH82HM3XF/10CG24N9S\n" + "H-4WEH82HD3X/OF10CG220N9K4\n" + "H-4WEH82HE3XF/10CW230N9TDKL\n" + "H-4WEH82HE3XF/10CG24NSDZ/13SO6\n" + "H-4WEH82HE3XF/10CG24N9SDL\n" + "H-4WEH82HE3X/10CG24N9ESDKL/B10D2\n" + "H-4WEH82HE3X/10CG24N9Z5L\n" + "H-4WEH82HE3X/10CG24N9K4\n" + "H-4WEH82HC3XF/10CG24N9K4\n" + "H-4WEH82HJ3XF/10CW110N9DAL/V\n" + "H-4WEH82HJ3X/10CG24N9S2K4\n" + "H-4WEH82HE3XF/10CG24N9SK4/13\n" + "H-4WEH82HE3X/10CG24N9SZ5L\n" + "H-4WEH82HC3XF/10CG24N9S/13\n" + "H-4WEH82HE3X/16AG24NS2Z5L/13SO35\n" + "H-4WEH82HE3X/10CG24NSDZL\n" + "H-4WEH82HE3XF/10CG24N9S/13\n" + "H-4WEH82HJ3X/10CG24NSDZL\n" + "H-4WEH82HD3XF/OF10EG220N9SK4\n" + "H-4WEH82HD3XF/10CG24N9S2K4/42B10\n" + "H-4WEH82HE3XF/10CG24N9K4\n" + "H-4WEH82HE3XF/10CG24NDLSO847\n" + "H-4WEH82HD3XF/10CG24N9K4\n" + "H-4WEH82HD3XF/OF10CG220N9SK4\n" + "H-4WH82HG3XF/\n" + "H-4WEH82HF3XF/10CW220N9S2\n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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