c#中的正则表达式负前瞻 [英] Regex negative lookahead in c#
本文介绍了c#中的正则表达式负前瞻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要匹配 ["this"
而不是 :["this"
I need to match ["this"
but not :["this"
我有这个代码:
Match match = Regex.Match(result, @"\[""(.*?)""",
RegexOptions.IgnoreCase);
while (match.Success)
{
MessageBox.Show(match.Groups[1].Value.Trim());
}
我尝试了模式 @"(?!:)\[""(.*?)"""
,但它仍然匹配 :["this"
>.我需要什么模式才能实现这一目标?
I have tried the pattern @"(?!:)\[""(.*?)"""
, but it still match :["this"
. Whats the pattern I need to achieve this?
推荐答案
当你想向后看(在字符串中向左)时,你正在向前看(在字符串中向右).
You are looking ahead (rightwards in the string) when you want to be looking behind (leftwards in the string).
尝试 @"(?<!:)\[""(.*?)"""
代替.
这篇关于c#中的正则表达式负前瞻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文