zsh-workers
 help / color / mirror / code / Atom feed
From: stephane@chazelas.org
To: Peter Stephenson <p.w.stephenson@ntlworld.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Extending regexes
Date: Wed, 06 Jul 2022 19:40:01 +0100	[thread overview]
Message-ID: <f73d67233f9db547c055a461d8d7255d@chazelas.org> (raw)
In-Reply-To: <76883431.1281129.1656942459330@mail2.virginmedia.com>

FWIW, ast's extended and augmented regexps as supported by ksh93's [[ =~ 
]] operator or more generally in globs after ~(E) (extended) ~(A) 
(augmented) do have AND and NOT operator.

That's \& and \! in ERE and & and ! in ARE.

ere() ksh -c '[[ $1 =~ $2 ]]' ksh "$@"
are() ksh -c '[[ $1 =~ (?A)$2 ]]' ksh "$@"

And then you can do

ere x '^([[:lower:]]\&.)$'
ere y '^x\!$'

are x '^([[:lower:]]&.)$'
are y '^x!$'

Also note that AND(A,B) can be done with NOT(OR(NOT(A), NOT(B))) so even 
ksh88 or bash can do AND in their globs (with extglob in bash) with 
!(!(A)|!(B))

-- 
Stephane



  parent reply	other threads:[~2022-07-06 18:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-04 12:03 Sebastian Gniazdowski
2022-07-04 13:47 ` Peter Stephenson
2022-07-04 19:15   ` Bart Schaefer
2022-07-04 19:41     ` Peter Stephenson
2022-07-06 10:03       ` Daniel Shahaf
2022-07-06 18:40   ` stephane [this message]
2022-07-06 23:07 ` Phil Pennock
2022-07-07  0:22   ` Bart Schaefer

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=f73d67233f9db547c055a461d8d7255d@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).