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>62)(?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>5X)(?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>Y|)(?P<spool_position_monitoring>Y|)(?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<seal_material>V|)(?P<additional_details>)$\n";
final String string = "H-4WEH62HE5XF/10EG24N9S2K4\n"
+ "H-4WEH62HD5XF/OF10EG220N9SK4/B10V\n"
+ "H-4WEH62HH5XF/10EG24N9K4\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