From: rob@plan9.att.com
To: sam-fans@hawkwind.utcs.toronto.edu
Subject: Re: s cmd lossage
Date: Wed, 26 Jul 1995 11:29:33 -0400 [thread overview]
Message-ID: <95Jul26.113150edt.24103@hawkwind.utcs.utoronto.ca> (raw)
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
next reply other threads:[~1995-07-26 15:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-07-26 15:29 rob [this message]
-- strict thread matches above, loose matches on Subject: below --
1995-06-26 14:37 goon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=95Jul26.113150edt.24103@hawkwind.utcs.utoronto.ca \
--to=rob@plan9.att.com \
--cc=sam-fans@hawkwind.utcs.toronto.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).