I'd like to remove everything apart of my pattern match.For example I've the following line:window.page4_callback([here \is\ some text]);and I'd like to leave the text only within the double quotes, so the expected output is:here \is\ some text Matching pattern is /.* and its removal can be performed by using substitute::s/.*//ghowever how do you do opposite?I've tried to use vglobal (:v/pattern/d), but it would normally remove the whole line, but in my case it's saying:Pattern found in every line: .*I've found similar issue here, but I'm even more confused.
How to delete part of a line that does not match a pattern?
regular expression;substitute
There are probably a bunch of ways to do this; here's my attempt::%s/.*\(.\{-}\).*/\1/The key part is \(.\{-}\); this non-greedily matches everything in between quotes. This will match:window.page4_callback([here is some text]);The parentheses are there to start a subgroup, so we can reference it with \1 on the replacing side. We surround this with .* on both ends to match the rest of the line.So this doesn't really delete a non-matching pattern, as the title says. Rather, it deletes the entire line, and replaces it with a specific subgroup we matched earlier. The effect is the same, and for me, this is an easier way to think about it.Conclusion: capturing subgroups is good. Subgroups are your friends.EditTo also work after your edited post :-):%s/^.\{-}\(.*\).\{-}$/\1/This is a variant of the above, but notice we use .\{-} before and after the    now, to match as little as possible; plus, we anchor it to the start and end of the line with ^ and $.You can then replace the \ with a second :substitute command::%s/\\//This still won't work with something like:window.function(arg1, arg2);This will leave you with:arg1, arg2But I'm not sure if that's a requirement :-)