C# VS 2015查找并替换此字符串,但不替换该字符串
我正在使用VS regex尝试删除字符串Windows.Forms,但不是System.Windows.Forms 我可以用它来查找所有行: ^(?!*System.Windows.Forms).Windows.Forms$C# VS 2015查找并替换此字符串,但不替换该字符串,c#,regex,visual-studio,C#,Regex,Visual Studio,我正在使用VS regex尝试删除字符串Windows.Forms,但不是System.Windows.Forms 我可以用它来查找所有行: ^(?!*System.Windows.Forms).Windows.Forms$ 但我不能用替换,因为它显然删除了整行。有什么想法吗?您只需将“向后看”调整为 (?<!System\.)Windows\.Forms (? 或者更精确地说,使用单词边界: (?<!\bSystem\.)\bWindows\.Forms\b (? 见 look
但我不能用替换,因为它显然删除了整行。有什么想法吗?您只需将“向后看”调整为
(?<!System\.)Windows\.Forms
(?
或者更精确地说,使用单词边界:
(?<!\bSystem\.)\bWindows\.Forms\b
(?
见
lookback是在当前位置遇到某些子模式之前检查文本。因此,您需要匹配和使用的文本是Windows.Forms
,但不应在前面加上System.
。因此,lookback(负数)只应包含System\。
(或\bSystem\。
)
请注意,点必须转义以匹配文字点。效果很好。谢谢!