[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: |
Sun, 12 Nov 2023 08:26:26 +0100 |
On Sun, Nov 12, 2023 at 08:03:18AM +0100, Michael Heerdegen wrote:
> Edgar Lux <edgarlux@mailfence.com> writes:
>
> > 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")))
>
> No,
[...]
> I think `match a string not starting with "ab"' is not even expressible
> using a standalone standard regexp. That would require regexps to be
> able to backtrack when matching, and it would be something more general
> than regexps.
Actually... the complement of a regular language is also a regular
language, so there should be a regexp for that, too. But regexps
don't seem to have a negation operator very often, do they? (I
know of negated lookarounds, e.g. in PCRE, but...)
Off the bat I don't know of a general way to construct a regexp
matching the complement of a language.
In the above, case, you might just do something like "[^a].|.[^b]",
if I'm not making an off-by-one error (yes, I'm missing "^.$" ;-)
It reminds one of De Morgan...
So in rx, (not (seq "a" "b")) might rather correspond to something
like (or (seq (not "a") anychar) (seq anychar (not "b"))) modulo
corner cases like an "one char sequence", which also wouldn't be
"ab".
Cheers
--
t
signature.asc
Description: PGP signature
- How to get a concatenation of the negations with rx (ex: [^a][^b])?, Edgar Lux, 2023/11/11
- Re: How to get a concatenation of the negations with rx (ex: [^a][^b])?, Michael Heerdegen, 2023/11/12
- Re: How to get a concatenation of the negations with rx (ex: [^a][^b])?,
tomas <=
- Re: How to get a concatenation of the negations with rx (ex: [^a][^b])?, Yuri Khan, 2023/11/12
- Re: How to get a concatenation of the negations with rx (ex: [^a][^b])?, tomas, 2023/11/12
- Re: How to get a concatenation of the negations with rx (ex: [^a][^b])?, Michael Heerdegen, 2023/11/12
- RE: How to get a concatenation of the negations with rx (ex: [^a][^b])?, Anders Munch, 2023/11/13
- Re: How to get a concatenation of the negations with rx (ex: [^a][^b])?, tomas, 2023/11/13
Re: How to get a concatenation of the negations with rx (ex: [^a][^b])?, Emanuel Berg, 2023/11/13