Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Regex代表;不是";成群结队_Java_Regex - Fatal编程技术网

Java Regex代表;不是";成群结队

Java Regex代表;不是";成群结队,java,regex,Java,Regex,我有一个正则表达式: <(\d+)>(\w+\s\d+\s\d+(?::\d+){2})\s([\w\/\.\-]*)(.*) (\w+\s\d+\s\d+(?:\d+{2})\s([\w\/\.\-]*)(.*)) 如果第三组是“MSWinEventLog”,我想做的是返回FALSE(不匹配),其余的返回“matched” <166>Apr 28 10:46:34 AMC the remaining phrase <11>Apr 28 10:46:34

我有一个正则表达式:

<(\d+)>(\w+\s\d+\s\d+(?::\d+){2})\s([\w\/\.\-]*)(.*)
(\w+\s\d+\s\d+(?:\d+{2})\s([\w\/\.\-]*)(.*))
如果第三组是“MSWinEventLog”,我想做的是返回FALSE(不匹配),其余的返回“matched”

<166>Apr 28 10:46:34 AMC the remaining phrase
<11>Apr 28 10:46:34 MSWinEventLog the remaining phrase
<170>Apr 28 10:46:34 Avantail the remaining phrase
<171>Apr 28 10:46:34 Avantail the remaining phrase
<172>Apr 28 10:46:34 AMC the remaining phrase
<173>Apr 28 10:46:34 AMC the remaining phrase
<174>Apr 28 10:46:34 Avantail the remaining phrase
<175>Apr 28 10:46:34 AMC the remaining phrase
<176>Apr 28 10:46:34 AMC the remaining phrase
<177>Apr 28 10:46:34 Avantail the remaining phrase
<178>Apr 28 10:46:34 AMC the remaining phrase
<179>Apr 28 10:46:34 Avantail the remaining phrase
<180>Apr 28 10:46:34 Avantail the remaining phrase
Apr 28 10:46:34 AMC剩余的短语
4月28日10:46:34 MSWinEventLog剩余的短语
4月28日10:46:34 Avantail剩余的短语
4月28日10:46:34 Avantail剩余的短语
4月28日10:46:34 AMC剩余的短语
4月28日10:46:34 AMC剩余的短语
4月28日10:46:34 Avantail剩余的短语
4月28日10:46:34 AMC剩余的短语
4月28日10:46:34 AMC剩余的短语
4月28日10:46:34 Avantail剩余的短语
4月28日10:46:34 AMC剩余的短语
4月28日10:46:34 Avantail剩余的短语
4月28日10:46:34 Avantail剩余的短语
如何将“NOT
MSWinEventLog
”放入正则表达式组
([\w\/\.\-]*)

注:
上面的第二个短语应该返回“notmatched”(\w+\s\d+\s\d+(?:\d+{2})\s(?!MSWinEventLog)([\w\/\.\-]*)(.*)) (这里:“
(?!MSWinEventLog)
”)应该足够了:

如果您希望匹配某个内容而不是紧跟其后的其他内容,则必须进行负前瞻
在解释字符类时,我已经解释了为什么不能使用否定来匹配后面没有“u”的“q”。负前瞻提供了解决方案:
q(?!u)


您可以使用“负前瞻”来执行此操作:

<(\d+)>(\w+\s\d+\s\d+(?::\d+){2})\s(?!MSWinEventLog)([\w\/.-])(.)
                                   -----------------
(\w+\s\d+\s\d+(?:\d+{2})\s(?!MSWinEventLog)([\w\/.-])()
-----------------

(?!MSWinEventLog)
只有在后面紧跟着一个匹配“MSWinEventLog”的表达式时才会匹配。

哈哈,这正是我想要的答案。无论如何,非常感谢你。
<(\d+)>(\w+\s\d+\s\d+(?::\d+){2})\s(?!MSWinEventLog)([\w\/.-])(.)
                                   -----------------