Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cs.utexas.edu!jsq From: eric@mks.com (Eric Gisin) Newsgroups: comp.std.unix Subject: ed s/a*/./g description Message-ID: <17832@cs.utexas.edu> Date: 8 Feb 91 20:35:50 GMT Sender: jsq@cs.utexas.edu Organization: Mortice Kern Systems Inc., Waterloo, Ontario, CANADA Lines: 25 Approved: jsq@cs.utexas.edu (Moderator, John S. Quarterman) X-Submissions: std-unix@uunet.uu.net Submitted-by: eric@mks.com (Eric Gisin) Does anyone have an complete description of how s///g and awk's gsub handle the special case of an empty pattern match? The System V documents and POSIX.2 don't cover this. For example, the command s/[a-z]*/./g does the following on System V ed: -bug- becomes .-.-. The following algorithm produces an extra dot: -bug- becomes .-..-. gsub(pattern, replace, src, dst) while (1) { find next pattern in src copy part before match from src to dst copy replace to dst advance src to end of match if (at end of src) break; /* special case for empty match */ if (match was empty) *dst++ = *src++; } Volume-Number: Volume 22, Number 118