我有一個模式在日誌如下:正則表達式匹配否定
| App: | -> which doesn't have the app information
| App: Registration | -> which indicates that this is registration app.
我希望能夠找到從日誌中| App: |
的。
我試過下面的正則表達式但失敗了,所以決定在這裏問。
/App: ^(.*) |?/g
和其他一些但失敗。
幫助表示讚賞。
我有一個模式在日誌如下:正則表達式匹配否定
| App: | -> which doesn't have the app information
| App: Registration | -> which indicates that this is registration app.
我希望能夠找到從日誌中| App: |
的。
我試過下面的正則表達式但失敗了,所以決定在這裏問。
/App: ^(.*) |?/g
和其他一些但失敗。
幫助表示讚賞。
你必須逃避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));
我試過了「App:\ |」但沒有工作。 – DarthVader
Wellll ...你也必須逃避反斜線:)哈哈,它就像一個非常糟糕的惡作劇,Java的人正在玩你!請參閱上面的ProgrammersBlock代碼示例。 – Barett
你試過'/ | App:|/g'?或'/ |應用程序:* |/g'在多個空格的情況下。 – Andreas
你想在'Java'或'C#'中使用這個正則表達式嗎 –