import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "Initiated logon request((?!Received logon)[\\s\\S])*Received logon";
final String string = "<20170503-18:19:09, FIXT.1.1:BANZAI->EXEC, event> (Initiated logon request)\n"
+ " <20170503-18:19:09, FIX.4.4:BANZAI->EXEC, incoming> (8=FIX.4.4☺9=67☺35=A☺\n"
+ " 34=177☺49=EXEC☺52=20170503-18:19:09.298☺56=BANZAI☺98=0☺108=30☺10=092☺)\n"
+ " <20170503-18:19:09, FIX.4.4:BANZAI->EXEC, event> \n"
+ " (Received logon) fdsfhffghgfhgjgf 177☺49=EXEC☺52=20170503-18:19:09.298☺\n"
+ " 56=BANZAI☺98 (Received logon) more stuff after this....";
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