[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Empty matches in global search (string library versus sed)
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 27 Feb 2008 12:37:32 -0300
> In string.gmatch and string.gsub, when an empty (zero-length) match is
> encountered, it is always accepted; the search position is then incremented
> by 1 character.
> ("ab"):gsub(".*", "#") --> "##", 2
> ("ab"):gsub("a*", "#") --> "##b#", 3
> In sed's "s" command (with "g" flag), when an empty match is encountered,
> it is accepted only if it's not adjacent to the previous match, otherwise
> it's ignored.
> * I'm not proficient with sed; feel free to correct me.
> * Python's re.sub behaves (in regard to empty matches) like sed.
> a) which behavior seems more intuitive?
> b) if it's that of sed, is it worthwhile for string library (in 5.2) to
> adopt sed's handling of empty matches?
For me none of them is intuitive. (In particular, the Lua behavior
is only a way to avoid an infinite loop, which would be the correct
[if not the intuitive] behavior.)