import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^\\$.*LOB.*00 &$";
final String string = "$90TM020516 19002200&\n"
+ "$90LOB 0 0 0 7 10 &\n"
+ "$90LOB 25 0 0 6 10 &\n"
+ "$90LOB 57 0 0 6 10 &\n"
+ "$90LOB353 0 0 5 10 &\n"
+ "$90LOB 36 0 0 5 10 &\n"
+ "$90GPSA8 0 38281168 -77448376&\n"
+ "$90LOB276 0 0 5 10 &\n"
+ "$90LOB185 0 0 6 10 &\n"
+ "$90LOB197 0 0 6 00 &\n"
+ "$90LOB198 0 254 6 00 &\n"
+ "$90LOB197 0 254 6 00 &\n"
+ "RSSI $90LOB201 0 254 5 00 &\n"
+ "$90TM020516 19002300&\n"
+ "$90LOB194 0 254 5 00 &\n"
+ "$90LOB190 0 254 5 00 &\n"
+ "$90LOB185 0 254 5 00 &\n"
+ "$90LOB181 0 254 5 00 &\n"
+ "$90LOB187 0 254 5 00 &\n"
+ "$90LOB192 0 254 5 00 &\n"
+ "$90LOB195 0 254 5 00 &\n"
+ "$90LOB195 0 254 5 00 &\n"
+ "$90LOB191 0 254 5 00 &\n"
+ "$90LOB184 0 254 5 00 &\n"
+ "$90LOB177 0 254 5 00 &";
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