sam-fans - fans of the sam editor
 help / color / mirror / Atom feed
* 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
* 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

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-06-26 14:37 s cmd lossage goon
1995-07-26 15:29 rob

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).