Regex Help - Greedy vs. Non-Greedy
freebsd at optimis.net
Wed Sep 9 17:46:48 UTC 2009
On Wed, Sep 09, 2009 at 09:15:25AM -0700, Drew Tomlinson wrote:
> I'm trying to do a search and replace in vim. I have lines like this:
> http://site2/dir/;LastName, FirstName;Phone;
> http://site3/dir/;LastName, FirstName;
> I'm want to match "http:*" and stop matching at the first ";". My basic
> regex is:
> 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.
LOL. Do yourself a favour and stop "Googling". Vim has a built-in help
system. To access help for regular expressions:
:he r[TAB] ...
and search for non-greedy (or just scroll down).
> How can I write a regex that stops matching at the first semi-colon?
You've already received a few answers, but I'll add one that may be even
better -- rely on external programs instead. Vim can be a bit clunky at
The simplest and most typical usage would be
If using Perl
$ perldoc -h
$ perldoc -q regex
More information about the freebsd-questions