我需要定义多模式以使用 String 进行编译,并且在运行后它应该给我在我的模式中具有相同格式的字符串中的任何内容。这是代码:
String line = "This order was places for QT 30.00$ !OK ? ";
Pattern[] patterns = new Pattern[]{
Pattern.compile("\\d+[.,]\\d+.[$] ", Pattern.CASE_INSENSITIVE),
Pattern.compile("\\d:\\d\\d",Pattern.CASE_INSENSITIVE | Pattern.MULTILINE)
}; // Create a Pattern object
// Now create matcher object.
for (Pattern scriptPattern : patterns){
Matcher m = scriptPattern.matcher(line);
System.out.println(m.group());
} }