[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Empty matches in global search (string library versus sed)
- From: Shmuel Zeigerman <shmuz@...>
- Date: Wed, 27 Feb 2008 17:08:42 +0200
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?