From: Ralph Corderoy <ralph@inputplus.co.uk>
To: coff@tuhs.org
Subject: [COFF] Re: Grep has gone overboard
Date: Mon, 30 May 2022 09:26:23 +0100 [thread overview]
Message-ID: <20220530082623.A126121F8A@orac.inputplus.co.uk> (raw)
In-Reply-To: <9BBE9119-B5BF-4C4A-B22E-928C37470BA9@iitbombay.org>
Hi Bakul,
> Forgot to add, you can solve this another way (taking the abc
> example):
> grep ‘^...$’ | grep ‘[^a]*a[^a]*’ | grep ‘[^b]*b[^b]*’ | grep ‘[^c]*c[^c]*’
I know you know this and the error is just from typing an email, but in
case other listeners are following along, all the greps need start and
end-of-line anchors.
Without them,
grep '[^a]*a[^a]*'
still matches ‘aa’ because there are zero non-a before the first a, then
the first a matches, and there are zero non-a after it. Here's ‘aa’
with indexes between the characters.
a a
0 1 2
[^a]* matches 0-0
a matches 0-1
[^a]* matches 1-1
And it's easier to invert the test into
grep -v 'a.*a'
I'll stop waffling on about regexps now. Though I do have a SNOBOL4
question for TUHS which I should get around to writing. :-)
--
Cheers, Ralph.
next prev parent reply other threads:[~2022-05-30 8:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-30 4:12 [COFF] " Dave Horsfall
2022-05-30 4:47 ` [COFF] " Bakul Shah
2022-05-30 6:35 ` Michael Kjörling
2022-05-30 6:51 ` Bakul Shah
2022-05-30 8:26 ` Ralph Corderoy [this message]
2022-05-30 8:01 ` Ralph Corderoy
2022-05-30 8:16 ` Ralph Corderoy
2022-05-30 8:43 ` Bakul Shah
2022-05-30 9:19 ` Ralph Corderoy
2022-05-30 7:38 ` Ralph Corderoy
2022-05-30 7:44 ` Ralph Corderoy
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=20220530082623.A126121F8A@orac.inputplus.co.uk \
--to=ralph@inputplus.co.uk \
--cc=coff@tuhs.org \
/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).