import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^Maximum amplitude:\\s*(-?\\d\\.\\d+)\\n";
final String string = "Samples read: 6615000\n"
+ "Length (seconds): 75.000000\n"
+ "Scaled by: 2147483647.0\n"
+ "Maximum amplitude: 0.712219\n"
+ "Minimum amplitude: -0.805969\n"
+ "Midline amplitude: -0.046875\n"
+ "Mean norm: 0.009264\n"
+ "Mean amplitude: -0.000027\n"
+ "RMS amplitude: 0.043011\n"
+ "Maximum delta: 0.734100\n"
+ "Minimum delta: 0.000000\n"
+ "Mean delta: 0.008353\n"
+ "RMS delta: 0.041470\n"
+ "Rough frequency: 6767\n"
+ "Volume adjustment: 1.241";
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