我在日志中有如下模式:
| App: | -> which doesn't have the app information
| App: Registration | -> which indicates that this is registration app.
我希望能够从日志中找到| App: |
个。
我试过跟随正则表达但失败了,所以决定在这里问。
/App: ^(.*) |?/g
和其他一些人但失败了。
帮助表示赞赏。
答案 0 :(得分:1)
您必须在Java中转义垂直条。在它自己的垂直条上是一个正则表达式的运算符。 https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
String test = "| App: | ABC";
String test2 = "| App: Registration |";
String match = "\\| App:.*\\|.*";
System.out.println(test.matches(match));
System.out.println(test2.matches(match));