Reputation: 235
I am using VS regex to try and delete the string Windows.Forms but not System.Windows.Forms
I can use this to find all of the lines:
^(?!.*System.Windows.Forms).Windows.Forms.$
But I cant use a replace for that since it obviously deletes the whole line. Any ideas?
Upvotes: 1
Views: 103
Reputation: 626802
You just need to adjust the lookbehind to
(?<!System\.)Windows\.Forms
Or with word boundary to be more precise:
(?<!\bSystem\.)\bWindows\.Forms\b
See the regex demo
The lookbehind is checking the text before the current position meets some subpattern. So, the text you need to match and consume is Windows.Forms
, but it should not be preceded with System.
. Thus, the lookbehind (negative one) should only contain System\.
(or \bSystem\.
).
Note that the dots must be escaped to match literal dots.
Upvotes: 3