import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^.*\\bgetHouseName:\\h+(.+)(?:\\R(?!.*price).*)*\\R.*price\\h+\\(in doll\\)\\h+\\[min:\\h+(\\d+,\\h+max:\\h+(\\d+))\\](?:\\R(?!.*squaremtr).*)*\\R.*squaremtr\\h+\\(in doll\\)\\h+\\[min: (\\d+)";
final String string = "[04:04:04s] [startedRetrieving]getHouseName: house1\n"
+ "[04:04:04s] [startedRetrieving]random useless text\n"
+ "[04:04:04s] [startedRetrieving]price (in doll) [min: 1000, max: 1200]\n"
+ "[04:04:05s] [startedRetrieving]squaremtr (in doll) [min: 75, max:85]\n"
+ "[04:04:04s] [startedRetrieving]sellVal (in doll) [min: 1000, max: 1200]\n"
+ "[04:04:05s] [startedRetrieving]random useless text\n"
+ "[04:04:05s] [startedRetrieving]random useless text\n"
+ "[04:04:05s] [startedRetrieving]random useless text\n"
+ "[04:04:05s] [startedRetrieving]rentPrice(in doll) [min: 150, max: 200]\n"
+ "[04:06:04s] [startedRetrieving]getHouseName: house2\n"
+ "[04:06:04s] [startedRetrieving]price(in doll) [min: 1004, max 1100]\n"
+ "[04:06:04s] [startedRetrieving]squaremtr(in doll) [min: 85, max 99]\n"
+ "[04:06:04s] [startedRetrieving]sellVal(in doll) [min: 950, max: 1050]\n"
+ "[04:06:04s] [startedRetrieving]random useless text\n"
+ "[04:06:04s] [startedRetrieving]rentPrice(in doll) [min: 150, max: 290]\n"
+ "[04:09:04s] [startedRetrieving]getHouseName: house3\n"
+ "[04:09:04s] [startedRetrieving]price(in doll) [min: 1099, max: 1200]\n"
+ "[04:09:04s] [startedRetrieving]squaremtr(in doll) [min: 90, max: 110]\n"
+ "[04:09:04s] [startedRetrieving]random useless text\n"
+ "[04:09:04s] [startedRetrieving]random useless text\n"
+ "[04:09:04s] [startedRetrieving]sellVal(in doll) [min: 1100, max: 1300]\n"
+ "[04:09:04s] [startedRetrieving]random useless text\n"
+ "[04:09:04s] [startedRetrieving]rentPrice(in doll) [min: 199, max: 300]";
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