🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.unix
Article #761

ed s/a*/./g description

#761
From: Eric Gisin
Date: Fri, 08 Feb 1991 20:35
25 lines
1193 bytes
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
Technical Details
Message-ID: <17832@cs.utexas.edu>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cs.utexas.edu!jsq

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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