I am trying to use a regex for replacing text in a file (replace a full url with just protocol/domain/)::%s/\(https\?:\/\/.*?\/\).*/\1/gcUnfortunately .*? does not match the string, even trying to escape the ? quantifier? How should non-greedy quantifier be escaped in vim?
How to make regex matchers non-greedy?
regular expression
Vim's regex has special syntax for non-greedy versions of operators (it's kind of annoying, but you just have to memorize them): http://vimregex.com/#Non-GreedyThe non-greedy version of * is \{-}. So, simply replace .* with .\{-}::%s/\(https\?:\/\/.\{-}\/\).*/\1/gc