import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?:#JSGF) (?<version>V1.0) (?<encoding>[A-Z-0-9]+) (?<locale>[a-z]{2}-[A-Z]{2});$";
final String string = "#JSGF V1.0 UTF-8 hu-HU;\n"
+ "grammar planmaster.hu;\n"
+ "<command_change_odontogram> = ( <change_to> [ a ] <odontogram_mode> [ felvételére | felvételre ] ) | ( <odontogram_mode> felvétele ) ;\n"
+ "<change_to> = ( váltás | válts | menj | ugrás | ugorj ) ;\n"
+ "<odontogram_mode> = ( státuszra | státuszhoz | státusz ) {state} | ( kezelés | kezelésre | kezeléshez | lépésekre | lépésekhez ) {treatment} ;\n"
+ "<command_full_jaw> = <all> * ( alsó {lower} | felső {upper} ) [ fogsor | állkapocs | fogak | fog ] <all> * <status> ;\n"
+ "<all> = mind | összes | teljes ;\n"
+ "<status> = ( <status1> | <status2> | <status3> ) {status} ;\n"
+ "<status1> = ( ép | alaphelyzet | alaphelyzetbe ) {1} ;\n"
+ "<status2> = ( hiány | hiányzik ) {2} ;\n"
+ "<status3> = [ szekunder ] ( szuvas | szuvasodott | szuvasodás ) {3} ;\n"
+ "<tooth18> = ( 18as | 18-as | tizennyolcas | nyolcas | ( 18 as ) ) {18} ;\n"
+ "<tooth17> = ( 17es | 17-es | tizenhetes | hetes | ( 17 es ) ) {17} ;\n"
+ "<tooth16> = ( 16os | 16-os | tizenhatos | hatos ) {16} ;\n"
+ "<tooth_region> = ( bal {left} | jobb {right} ) ( felső {upper} | alsó {lower} ) ;\n"
+ "<tooth_number> = ( <tooth18> | <tooth17> | <tooth16> | és ) ;\n"
+ "<command_select> = ( ( <tooth_number> + ) | <tooth_region> <tooth_number> + ) [ fog | fogak ] ;\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