Date: Wed, 9 Sep 2009 18:26:57 +0200 From: Mel Flynn <mel.flynn+fbsd.questions@mailing.thruhere.net> To: freebsd-questions@freebsd.org Cc: Drew Tomlinson <drew@mykitchentable.net> Subject: Re: Regex Help - Greedy vs. Non-Greedy Message-ID: <200909091826.57212.mel.flynn%2Bfbsd.questions@mailing.thruhere.net> In-Reply-To: <4AA7D49D.8090002@mykitchentable.net> References: <4AA7D49D.8090002@mykitchentable.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wednesday 09 September 2009 18:15:25 Drew Tomlinson wrote: > I'm trying to do a search and replace in vim. I have lines like this: > http://site1/dir/; > http://site2/dir/;LastName, FirstName;Phone; > http://site3/dir/;LastName, FirstName; > http://site4/dir/; > > I'm want to match "http:*" and stop matching at the first ";". My basic > regex is: > > /http:.\+;/ > > But it's matching *all* the semi-colons. Thus I've Googled and tried > various incatations to try and make my regex "non-greedy" but I can't > seem to come up with the correct combination. > > How can I write a regex that stops matching at the first semi-colon? AFAIK, there's no greediness modifier in vim regex. However, you can use character classes to solve your problem: %s/http:[^;]\+/foo/g -- Mel
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200909091826.57212.mel.flynn%2Bfbsd.questions>