Regex Help - Greedy vs. Non-Greedy

Daniel Bye danielby at slightlystrange.org
Wed Sep 9 16:22:46 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://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?

Tested in vi, not vim:

 /http:[^;]*/

Dan

-- 
Daniel Bye
                                                                     _
                                              ASCII ribbon campaign ( )
                                         - against HTML, vCards and  X
                                - proprietary attachments in e-mail / \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20090909/cc52fa42/attachment.pgp


More information about the freebsd-questions mailing list