import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "graphiceq\\s*:((?:\\s*\\d++(?:,\\d++)?+(?:\\.\\d++)?+\\s++[+-]?+\\d++(?:\\.\\d++)?+[ \\t]*+(?:;|$))++)";
final String string = "# A 15-band graphic equalizer with ISO bands\n"
+ "GraphicEQ: 25 6; 40 4.5; 63 3; 100 1.5; 160 0; 250 0; 400 0; 630 0; 1000 0; 1600 0; 2500 0; 4000 0; 6300 1.5; 10,000 +3; 16,000 +3\n"
+ "# A custom graphic equalizer\n"
+ "GraphicEQ: 20.00 0.00; 25.00 -1.75; 30.00 -3.20; 35.00 -4.15; 40.00 -4.90; 45.00 -5.55; 50.00 -6.10; 60.00 -6.90; 70.00 -7.40; 80.00 -7.80; 90.00 -8.10; 100.00 -8.30\n\n"
+ "The regex used is more permissive than the original specification (https://sourceforge.net/p/equalizerapo/wiki/Configuration%20reference/#graphiceq-since-version-10):\n"
+ "- Gain value can be signed (+/-);\n"
+ "- Frequency can use a comma as thousand separator\n\n"
+ "The last class does not include the newline as whitespaces to allow matching the `$` as the end of line (multiline flag is used).";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | 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