[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] Foolish Perl Question

> Not perl only. Several other regex implementations have non-greedy
> matching. Python I know does, for example. Even .NET *hack, thrbff*, I
> think... 

No, sed does a greedy matching by default. For example, consider this:

[amar at sahyadri /amar] cat sed.data
"This is me" and this is me too"
[amar at sahyadri /amar]

Now if I run sed on it to replace the string in quotes with AMAR, here
is what I get:

[amar at sahyadri /amar] sed 's/".*"/AMAR/g' sed.data
[amar at sahyadri /amar]

Now see this:

[amar at sahyadri /amar] sed 's/"[^"]*"/AMAR/g' sed.data
AMAR and this is me too"

So here you can see that sed does a greedy matching.


Amarendra A. Godbole / Microsoft ``Services For UNIX'' / These opinions
are _MINE_.
Love like there is no tomorrow !

This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.