[ale] Foolish Perl Question

Amarendra Godbole (Intl Vendor) v-amarg at microsoft.com
Sat Mar 23 02:00:43 EST 2002


> 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
[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.

Cheers,
--amar

--
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.






More information about the Ale mailing list