# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?P<key>\w+) = (?P<val>[^\\]+)"
test_str = ("{\"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")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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 Python, please visit: https://docs.python.org/3/library/re.html