Regex 单行正则表达式中的负前瞻
我有以下测试字符串:Regex 单行正则表达式中的负前瞻,regex,Regex,我有以下测试字符串: /// <exception cref="x"><paramref name="a"/> is null.</exception> /// <exception cref="y"><paramref name="b"/> is null. -or- /// </exception>dfjhhdfhdfkjhdkjdfhkdfjhdf -or- ///为空。 ///是空的-或- ///dfjhhdfhd
/// <exception cref="x"><paramref name="a"/> is null.</exception>
/// <exception cref="y"><paramref name="b"/> is null. -or-
/// </exception>dfjhhdfhdfkjhdkjdfhkdfjhdf -or-
///为空。
///是空的-或-
///dfjhhdfhdfkjhdkjdfhkdfjhdf-或-
这是一个三行的字符串。所以我创建了带有单线标志的正则表达式来捕获带有点的新行。我的正则表达式是:
(<exception.+?>)(?<a>.+?)(?!<\/exception>)-or-
()(?):
前两行匹配,第二组包括
,尽管我已经指定了负前瞻(?!)
为什么会这样?如何根据-或-
的出现来匹配第二行?这可能有些过分,但您可以使用一个调和点来匹配-或-
,而无需传递结束标记:
<exception[^>]*>((?!</exception>).)*-or-
]*>((?!)*-或-
此正则表达式模式表示:
<exception[^>]*> match an opening <exception> tag
((?!</exception>).)* then match any content WITHOUT passing a closing </exception> tag
-or- match -or-
]*>匹配开头标记
((?!)*然后在不传递结束标记的情况下匹配任何内容
-或-匹配-或-
您想在这里匹配什么,逻辑是什么?