[ale] VI vs perl RE question

fletch at phydeaux.org fletch at phydeaux.org
Wed Feb 1 11:55:42 EST 2006


> Jim wrote:
>
>>I'm trying to use vi to search for something enclosed in quotes, using
>>perl RE I get a hit with $var =~/"(.*?)"/;  But using the same re in vi
>>
>>
> So this is, "a quote, possibly followed by something, followed by
> another quote".
> (The question mark is redundant, since * already means "0 or more
> occurrences".)

Nope. it's not redundant.  In Perl, quantifiers (*, +, ?, {n,m}) may be
followed by a ? to indicate that they should be "non-greedy" and match as
short a string as possible that allows the whole RE to still match (rather
than the normal behavior of trying to match as much as possible).

Basically ".*" would gobble up any intervening "s and then backtrack to
the last, whereas ".*?" gobbles up as few characters as possible and gets
the first ".

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org|  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U





More information about the Ale mailing list