import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "((?:\\\\033|\\e|\\\\x1B|\\\\x1b){1}(?:\\[(?:=|\\?|[0-9]*)[0-9]*[a-gA-GnmsuJKhlHL]{0,1}(?:(?:\\;[0-9]*)*m){0,1}))";
final String string = "0x7ffff00196a0 \"\\r\\r\\r\\033[9999B[\\033[m\\033[36madmin\\033[m@\\033[m\\033[32mLeonards_switch\\033[m] > \"\n"
+ "\\r routerboard: yes\\r\\n model: CRS112-8P-4S\\r\\n revision: r2\\r\\n serial-number: F1 4F0FC0637C\\r\\n firmware-type: qca8513 L \\r \\n f a c t o r y - f i r m w a r e : 6 . 4 7 . 1 0 \\r \\n c u r r e n t - f i r m w a r e : 6 . 4 7 . 1 0 \\r \\n u p g r a d e - f i r m w a r e : 6 . 4 7 . 1 0 \\r\n"
+ "\\x1b[1;31mHello \\x1b[2;37;41mWorld\n"
+ "\\033[38;2;1;22;252m\n"
+ "\\033[38;5;5m\n"
+ "\\033[48;5;5m\n"
+ "\\033[48;2;15;251;3m\n"
+ "\\033[0J\n"
+ "\\033[J\n"
+ "\\033[1J\n"
+ "\\033[3J\n"
+ "\\033[K\n"
+ "\\033[0K\n"
+ "\\033[u\n"
+ "\\033[s\n"
+ "\\033[8\n"
+ "\\033[7\n"
+ "\\033[m\n"
+ "\\033[6n\n"
+ "\\033[5G\n"
+ "\\033[=14h\n"
+ "\\033[=15l\n"
+ "\\033[?25h\n"
+ "\\033[?1049l";
final Pattern pattern = Pattern.compile(regex);
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