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: Anders Munch
Subject: RE: How to get a concatenation of the negations with rx (ex: [^a][^b])?
Date: Mon, 13 Nov 2023 08:46:15 +0000

tomas@tuxteam.de wrote:
> OK -- this was roughly my train of thought: build the NFA, then invert 
> that... OMG. Then I decided this is better left as an exercise to the reader.

At the DFA level it's easy.  So you can just convert the NFA to a DFA and work 
from there.  I did that exercise once upon a time, let me see if I can remember 
it.

First convert to DFA. For every node, add an outgoing edge to the acceptance 
state for every character that doesn't already have an outgoing node. Remove 
all edges to the acceptance state that were in the original DFA.

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.

regards,
Anders


reply via email to

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