sam-fans - fans of the sam editor
 help / color / mirror / Atom feed
* Re: s cmd lossage
@ 1995-07-26 15:29 rob
  0 siblings, 0 replies; 2+ messages in thread
From: rob @ 1995-07-26 15:29 UTC (permalink / raw)
  To: sam-fans

some time ago - i'm catching up on old sam mail - quanstro@sartre.minerva.bah.com said:

	this s command lost with the latest (straight from at&t)
	version of sam.
		s:(([A-Z][a-z]*[ ]?)+)[ 	]+([0-9]+):NAME	\1\nPHONE 205 \2\n:g
					^- space tab

	what happened was that \2 was set to \1.

i've tried it here and it works as written.  let me explain what's going on,
because i think you're also seeing it work correctly but it's confusing you.

i tried this source:
	ABCD	01234
and got
	NAME	ABCD
	PHONE	205 D
which is correct.  as it says in the manual, the \digit operators on the
right side of a substitution refer to the text matched by the subexpression
beginning at the digit-th left parenthesis. here \1 would refer to the match
of
	(([A-Z][a-z]*[ ]?)+)
which would be
	ABCD
and \2 would refer to the most recent match of
	([A-Z][a-z]*[ ]?)
which is
	D
confusion comes because of the nesting -- whose meaning is defined
by the manual -- and the repetition operator (+) -- whose meaning is
not but should be clear from any thought about the implementation.
referring to the implementation is the last refuge of the writer of
incomplete documentation, but i believe the behavior is reasonable.
you wrote a near-nonsense expression and got near-nonsense
results.  i see no bug here.

now you may have some input text that shows other behavior, but
if so please interpret the answer carefully before deciding there's a bug.
i don't deny there could be one, but nested repeated regexps can be
fertile sources of confusion as well as errors.

-rob


^ permalink raw reply	[flat|nested] 2+ messages in thread

* s cmd lossage
@ 1995-06-26 14:37 goon
  0 siblings, 0 replies; 2+ messages in thread
From: goon @ 1995-06-26 14:37 UTC (permalink / raw)
  To: sam-fans

this s command lost with the latest (straight from at&t)
version of sam.
	s:(([A-Z][a-z]*[ ]?)+)[ 	]+([0-9]+):NAME	\1\nPHONE 205 \2\n:g
				^- space tab

what happened was that \2 was set to \1. i rewrote the command without 
the nested parens (i really hadn't expected the command to work),
and things were Happy. the working rewritten command is
	s:([A-Za-z ]+)[ 	]+([0-9]+):NAME	\1\nPHONE 205 \2\n:g



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1995-07-26 15:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-07-26 15:29 s cmd lossage rob
  -- strict thread matches above, loose matches on Subject: below --
1995-06-26 14:37 goon

sam-fans - fans of the sam editor

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/sam-fans

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 sam-fans sam-fans/ http://inbox.vuxu.org/sam-fans \
		sam-fans@hawkwind.utcs.toronto.edu
	public-inbox-index sam-fans

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.sam-fans


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git