lua-users home
lua-l archive

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


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.
Examples:
  ("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.
Examples:
  s/.*/#/g
  ab
  #

  s/a*/#/g
  ab
  #b#

Notes:
*  I'm not proficient with sed; feel free to correct me.
*  Python's re.sub behaves (in regard to empty matches) like sed.

Questions:
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?

--
Shmuel