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: Sun, 24 Dec 2023 12:54:37 +0100

[...]

Late in this thread, but I fell into some
rabbit hole :)

> > The main problem is not implementation.  It's that it's not obvious what to 
> > use them for in the variable-length searches that regexes are typically 
> > used for.  It's just confusing that the string "abz" is a match for the 
> > regular expression "not ab", and if you were looking for a two-character 
> > string that is not "ab", then a general negation operator isn't going to 
> > help you, at least not by itself.
> 
> Yes, I guess this is more or less what I hand-waved away with
> my "modulo corner cases" (ain't natural language wonderful? ;)
> 
> For your example, one would have to append .* to all non-end
> anchored (i.e. those not ending with $) regexps to better match
> usual expectations. But who knows whether that's all.

Turns out that there is another, less known way to look at
at regular expressions. Here are two nice links i[1] [2] (the
second also shows that there are practical applications).

This "other way" actually has complement as one basic element
of the regexp language.

The regular languages defined there are equivalent to the
traditional ones, and at the end, finite automata are constructed
and all that, but boy, I'd have killed for "complement" some
time or other.

I have the hunch that complement is somehow related to (positive
and negative) lookahead and lookbehind as known from Perl,
but I'm not quite sure yet.

Enjoy

  Regular expressions and Brzozowski derivatives
  [1] https://en.wikipedia.org/wiki/Brzozowski_derivative
  [2] https://www.khoury.northeastern.edu/home/turon/re-deriv.pdf
-- 
tomás

Attachment: signature.asc
Description: PGP signature


reply via email to

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