Regular Expressions 101

Save & Share

  • Regex Version: ver. 8
  • 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
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<key>\\w+) = (?P<val>[^\\\\]+)"; final String string = "{\"global_quality\": \"[general]\\\n" + "version = 4\\\n" + "name = Benchy Jonas\\\n" + "definition = fdmprinter\\\n" + "\\\n" + "[metadata]\\\n" + "setting_version = 6\\\n" + "type = quality_changes\\\n" + "quality_type = normal\\\n" + "\\\n" + "[values]\\\n" + "acceleration_enabled = True\\\n" + "adhesion_type = skirt\\\n" + "bridge_settings_enabled = True\\\n" + "jerk_enabled = False\\\n" + "layer_height = 0.2\\\n" + "layer_height_0 = 0.2\\\n" + "magic_spiralize = False\\\n" + "material_bed_temperature = 50\\\n" + "material_bed_temperature_layer_0 = 50\\\n" + "retraction_combing = infill\\\n" + "speed_slowdown_layers = 1\\\n" + "support_enable = True\\\n" + "support_type = buildplate\\\n" + "travel_retract_before_outer_wall = True\\\n" + "\\\n" + "\", \"extruder_quality\": [\"[general]\\\n" + "version = 4\\\n" + "name = Benchy Jonas\\\n" + "definition = fdmprinter\\\n" + "\\\n" + "[metadata]\\\n" + "setting_version = 6\\\n" + "type = quality_changes\\\n" + "quality_type = normal\\\n" + "position = 0\\\n" + "\\\n" + "[values]\\\n" + "acceleration_infill = 1000\\\n" + "acceleration_print = 500\\\n" + "acceleration_roofing = 750\\\n" + "acceleration_topbottom = 1000\\\n" + "acceleration_travel = 1500\\\n" + "acceleration_wall_0 = 500\\\n" + "acceleration_wall_x = 750\\\n" + "alternate_extra_perimeter = False\\\n" + "bottom_layers = =999999 if infill_sparse_density == 100 else math.ceil(round(bottom_thickness / resolveOrValue('layer_height'), 4))\\\n" + "bottom_skin_preshrink = 1.4\\\n" + "bottom_thickness = 1.2\\\n" + "bridge_fan_speed = 75\\\n" + "bridge_fan_speed_2 = 25\\\n" + "bridge_fan_speed_3 = 33\\\n" + "brim_line_count = 2\\\n" + "brim_outside_only = False\\\n" + "coasting_enable = False\\\n" + "coasting_speed = 100\\\n" + "coasting_volume = 0.02\\\n" + "cool_fan_full_layer = 5\\\n" + "cool_fan_speed = 75\\\n" + "cool_fan_speed_max = =cool_fan_speed\\\n" + "cool_min_layer_time = 5\\\n" + "cool_min_layer_time_fan_speed_max = 20\\\n" + "cool_min_speed = 20\\\n" + "default_material_print_temperature = 230\\\n" + "fill_outline_gaps = False\\\n" + "gradual_infill_step_height = 2\\\n" + "gradual_infill_steps = 0\\\n" + "gradual_support_infill_step_height = 3\\\n" + "gradual_support_infill_steps = 1\\\n" + "infill_before_walls = False\\\n" + "infill_enable_travel_optimization = True\\\n" + "infill_line_distance = =0 if infill_sparse_density == 0 else (infill_line_width * 100) / infill_sparse_density * (2 if infill_pattern == 'grid' else (3 if infill_pattern == 'triangles' or infill_pattern == 'trihexagon' or infill_pattern == 'cubic' or infill_pattern == 'cubicsubdiv' else (2 if infill_pattern == 'tetrahedral' or infill_pattern == 'quarter_cubic' else (1 if infill_pattern == 'cross' or infill_pattern == 'cross_3d' else 1))))\\\n" + "infill_line_width = 0.5\\\n" + "infill_overlap = 5\\\n" + "infill_pattern = gyroid\\\n" + "infill_sparse_density = 7\\\n" + "infill_support_angle = 75\\\n" + "infill_support_enabled = False\\\n" + "ironing_flow = 8\\\n" + "ironing_inset = 0.25\\\n" + "ironing_line_spacing = 0.2\\\n" + "jerk_infill = 20\\\n" + "jerk_layer_0 = 7\\\n" + "jerk_print = 7\\\n" + "jerk_roofing = 10\\\n" + "jerk_support_infill = 20\\\n" + "jerk_support_interface = 20\\\n" + "jerk_topbottom = 20\\\n" + "jerk_travel = 20\\\n" + "jerk_travel_layer_0 = 7\\\n" + "jerk_wall_0 = 8\\\n" + "jerk_wall_x = 15\\\n" + "line_width = =machine_nozzle_size\\\n" + "material_diameter = 1.75\\\n" + "material_final_print_temperature = =max(-273.15, material_print_temperature - 15)\\\n" + "material_flow = 99\\\n" + "material_initial_print_temperature = =max(-273.15, material_print_temperature - 10)\\\n" + "material_print_temperature = 230\\\n" + "material_print_temperature_layer_0 = 230\\\n" + "min_infill_area = 10\\\n" + "optimize_wall_printing_order = True\\\n" + "retract_at_layer_change = False\\\n" + "retraction_amount = 0.8\\\n" + "retraction_count_max = 100\\\n" + "retraction_extra_prime_amount = 0\\\n" + "retraction_extrusion_window = =retraction_amount\\\n" + "retraction_hop = 0.2\\\n" + "retraction_hop_enabled = True\\\n" + "retraction_hop_only_when_collides = True\\\n" + "retraction_min_travel = 1\\\n" + "retraction_prime_speed = 25\\\n" + "retraction_retract_speed = 25\\\n" + "retraction_speed = 70\\\n" + "roofing_layer_count = 0\\\n" + "roofing_pattern = concentric\\\n" + "skin_no_small_gaps_heuristic = False\\\n" + "skin_overlap = =5 if top_bottom_pattern != 'concentric' else 0\\\n" + "skirt_brim_line_width = =line_width\\\n" + "skirt_brim_minimal_length = 175\\\n" + "skirt_brim_speed = 20\\\n" + "skirt_gap = 5\\\n" + "skirt_line_count = 3\\\n" + "speed_equalize_flow_enabled = False\\\n" + "speed_equalize_flow_max = 60\\\n" + "speed_infill = 50\\\n" + "speed_ironing = 60\\\n" + "speed_layer_0 = 20\\\n" + "speed_print = 50\\\n" + "speed_roofing = 50\\\n" + "speed_support = 50\\\n" + "speed_support_infill = 60\\\n" + "speed_support_interface = 50\\\n" + "speed_topbottom = 50\\\n" + "speed_travel = 175\\\n" + "speed_wall = =speed_print / 2\\\n" + "speed_wall_0 = 25\\\n" + "speed_wall_x = =speed_wall * 2\\\n" + "support_angle = 67\\\n" + "support_infill_rate = 10\\\n" + "support_infill_sparse_thickness = =resolveOrValue('layer_height')\\\n" + "support_interface_density = 50\\\n" + "support_interface_enable = True\\\n" + "support_interface_pattern = lines\\\n" + "support_interface_skip_height = 0.2\\\n" + "support_line_width = 0.5\\\\nsupport_minimal_diameter = 2\\\n" + "support_offset = 0.4\\\n" + "support_pattern = zigzag\\\n" + "support_roof_height = 1\\\n" + "support_top_distance = =extruderValue(support_roof_extruder_nr if support_roof_enable else support_infill_extruder_nr, 'support_z_distance')\\\n" + "support_tower_diameter = 5\\\n" + "support_tower_roof_angle = 30\\\n" + "support_use_towers = True\\\n" + "support_wall_count = 1\\\n" + "support_xy_distance = 0.6\\\n" + "support_xy_distance_overhang = 0.5\\\n" + "support_xy_overrides_z = xy_overrides_z\\\n" + "support_z_distance = 0.2\\\n" + "top_bottom_pattern = lines\\\n" + "top_bottom_pattern_0 = lines\\\n" + "top_bottom_thickness = 1.6\\\n" + "top_layers = =0 if infill_sparse_density == 100 else math.ceil(round(top_thickness / resolveOrValue('layer_height'), 4))\\\n" + "top_skin_preshrink = 1.2\\\n" + "top_thickness = 1.6\\\\ntravel_avoid_other_parts = False\\\n" + "travel_avoid_supports = True\\\n" + "travel_compensate_overlapping_walls_0_enabled = =travel_compensate_overlapping_walls_enabled\\\n" + "travel_compensate_overlapping_walls_enabled = False\\\n" + "travel_compensate_overlapping_walls_x_enabled = =travel_compensate_overlapping_walls_enabled\\\n" + "wall_0_wipe_dist = =machine_nozzle_size / 2\\\n" + "wall_line_count = 3\\\n" + "wall_line_width_0 = 0.4\\\n" + "wall_line_width_x = =wall_line_width\\\n" + "wall_thickness = 2\\\n" + "xy_offset_layer_0 = -0.05\\\n" + "z_seam_corner = z_seam_corner_inner\\\n" + "z_seam_relative = True\\\n" + "z_seam_type = back\\\n" + "z_seam_x = -250\\\n" + "z_seam_y = -30\\\n" + "\\\n" + "\"]}\n\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