import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "([M,F]\\/\\d{2}\\/((\\d{1}((\\')|(\\’))?(([0,2-9]|1[0-1]?)((\\\")|(\\'\\')|(\\”))?)?)|\\d{1,3}cm|[1-2]m(\\d{1,2}(cm)?)?)\\s?\\[\\d{2,3}\\s?(lbs|kg)\\s?to\\s?\\d{2,3}\\s?(lbs|kg)\\]\\s?\\(((\\d{1,2}\\s?years?)|(([2-9]|1[0-1]?)\\s?months?)|(\\d{1,2}\\s?years?(\\;|\\,)?\\s?([0,2-9]|1[0-1]?)\\s?months?)|(([2-9]|1[0-1]?)\\s?weeks?))\\)\\s?(\\s?\\+\\s?\\(([DSBO]{1}:\\s?(\\d{2,3})\\s?(lbs|kg)(\\;|\\,))?\\s?([DSBO]{1}:\\s?(\\d{2,3})\\s?(lbs|kg)(\\;|\\,))?\\s?([DSBO]{1}:\\s?(\\d{2,3})\\s?(lbs|kg)(\\;|\\,))?\\s?[DSBO]{1}:\\s?(\\d{2,3})\\s?(lbs|kg)\\))?.*)|(^\\[Meta\\].*)";
final String string = "\n"
+ "M/20/5'10\" [150lbs to 180lbs] (2 years; 6 months) + (B: 300lbs; S: 410lbs; D: 480lbs) \n\n"
+ "F/26/5'2\" [52kg to 59kg] (5 years) \n\n"
+ "M/35/6'3\" [203lbs to 175lbs] (7 months) - Additional comments here \n\n"
+ " M/20/5'10\" [150lbs to 180lbs] (2 years; 6 months) + (B: 300lbs; S: 410lbs; D: 480lbs) ";
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