help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get a concatenation of the negations with rx (ex: [^a][^b])?


From: tomas
Subject: Re: How to get a concatenation of the negations with rx (ex: [^a][^b])?
Date: Mon, 13 Nov 2023 20:26:06 +0100

On Sat, Nov 11, 2023 at 10:00:12PM +0100, Emanuel Berg wrote:
> Edgar Lux wrote:
> 
> > Hello. I am trying to get this regular expression:
> >
> >     "[^a][^b]"
> >
> > in an easier way. I thought that I could do
> >
> >     (rx (not (seq "a" "b")))
> >
> > but that got me
> >
> >     Debugger entered--Lisp error: (error "Illegal argument
> >     to rx ‘not’: (seq \"a\" \"b\")")
> >
> > The error is very clear, but I would like to know if there
> > is a smart way of achieving the same without having to type:
> >
> >     (rx (seq (not "a") (not "b")))
> >
> > which produces
> >
> >     "[^a][^b]"
> 
> (rx (not (any "a" "b")))
> 
> "[^ab]"

(string-match "[^a][^b]" "ba")
  => 0 ; note: 0 means it found a match at pos 0

(string-match "[^ab]" "ba")
  => nil

No.

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]