Why there isn't negation operator for regular expression ?

Why there isn't negation operator for regular expression ?

Post by Michael Salm » Sat, 17 Sep 1994 17:51:52




|> Hi,
|>   In a regular expression, a '^' in [^abc] is a negation operator for
|> character set enclosed in "[]", but there isn't one for an entire expression
|> as one can suggest using "!" : so !(abc) matches all but a string "abc", or
|> (abc)(!(cde)) matches strings begining with "abc" followed by a string different
|> with "cde".
|>
|>   What the raison for this absence ?

It would be more traditional to say (cde)! which is short hand for
(cde){0,0}. I haven't tried it but it should work.

--

Michael Salmon

#include        <standard.disclaimer>
#include        <witty.saying>
#include        <fancy.pseudo.graphics>

Ericsson Telecom AB
Stockholm

 
 
 

Why there isn't negation operator for regular expression ?

Post by Stefan Monni » Sat, 17 Sep 1994 23:03:42




> It would be more traditional to say (cde)! which is short hand for
> (cde){0,0}. I haven't tried it but it should work.

Sorry, it doesn't !
What this mean is: it matches 0 occurences of "cde", which is the
empty string. And the empty string matches just about everything.

(just like "a{1,2}." matches "aaa")

The reason why the negation is absent is not totally clear to me, tho.
Maybe the implementation strategy generally used for regular
expressions isn't well suited for negation ?

        Stefan

 
 
 

Why there isn't negation operator for regular expression ?

Post by Zixiong Wa » Sat, 17 Sep 1994 00:33:04


Hi,
        In a regular expression, a '^' in [^abc] is a negation operator for
character set enclosed in "[]", but there isn't one for an entire expression
as one can suggest using "!" : so !(abc) matches all but a string "abc", or
(abc)(!(cde)) matches strings begining with "abc" followed by a string different
with "cde".

        What the raison for this absence ?

Zixiong WANG

Electricite de France

 
 
 

Why there isn't negation operator for regular expression ?

Post by th » Mon, 19 Sep 1994 18:45:53



> The reason why the negation is absent is not totally clear to me, tho.
> Maybe the implementation strategy generally used for regular
> expressions isn't well suited for negation ?

yeah, i think such patterns are not left-recursive (ie, requires more
state).

thi
--
------------------------------------------------------------------------------
thien-thi nguyen   <a href="ftp://ftp.netcom.com/pub/ttn/homepage.html>thi</a>

 
 
 

Why there isn't negation operator for regular expression ?

Post by Dan Merc » Wed, 21 Sep 1994 02:44:27




: |> Hi,
: |>         In a regular expression, a '^' in [^abc] is a negation operator for
: |> character set enclosed in "[]", but there isn't one for an entire expression
: |> as one can suggest using "!" : so !(abc) matches all but a string "abc", or
: |> (abc)(!(cde)) matches strings begining with "abc" followed by a string different
: |> with "cde".
: |>
: |>         What the raison for this absence ?

: It would be more traditional to say (cde)! which is short hand for
: (cde){0,0}. I haven't tried it but it should work.

in egrep, (cde)! matches cde!. (cde){0,0} matches everything.

: --

: Michael Salmon

: #include      <standard.disclaimer>
: #include      <witty.saying>
: #include      <fancy.pseudo.graphics>

: Ericsson Telecom AB
: Stockholm

--
Dan Mercer                                            ClearSystems, Inc

======================================================================
All opinions expressed are my own and do not reflect the opinions of
my employer or my employer's clients,  in particular 3M Company.
All advice or software offered or presented is provided As Is with no
warranty either expressed or implied.  Follow at your own risk.
Objects in the mirror are closer than they appear.

 
 
 

Why there isn't negation operator for regular expression ?

Post by Ade Bark » Wed, 21 Sep 1994 10:10:53


: The reason why the negation is absent is not totally clear to me, tho.
: Maybe the implementation strategy generally used for regular
: expressions isn't well suited for negation ?

Maybe... but at least for grep, one can invoke the -v option
to pass lines except those containing the pattern.

-Ade Barkah

 
 
 

Why there isn't negation operator for regular expression ?

Post by Tye McQue » Sat, 24 Sep 1994 08:12:28


: The reason why the negation is absent is not totally clear to me, tho.
: Maybe the implementation strategy generally used for regular
: expressions isn't well suited for negation ?

Perl 5 new has regexp's that support a couple of forms of
negation.  Wait a bit for the documentation to catch up with
the implementation and then fetch a copy, if you are interested.

We had to argue a while about exactly what negation should mean
but what we were really fighting over was just whether the
negative should be "anchored" or not (does "not 'xyz'" mean
"not exactly 'xyz'" or "does not contain 'xyz'").  Either way
you can add ".*" to remove unwanted anchoring or add "^" or "$"
to add missing anchoring.

There was also a lot of concern over how anchoring would affect
optimization of regexps (Perl optimizes regexps quite well) since
negation could be done in the Perl language outside of the regexp
itself and doing so might give much better performance than using
a general negation operator within the regexp.

Both of these issues may have played into negation not often being
included in regexp implementations.
---

             Nothing is obvious unless you are overlooking something

 
 
 

1. ksh regular expression @ operator and variables

In ksh, I set up 2 strings:

    colour="red"
    choices="red|white|blue"

Although the following test succeeds:


this one, using a variable for the colour choice, does not:


I cannot see why the use of variable $choices should fail.
I'd appreciate any help.  (Surely I'm missing something obvious??)

Strangely, when I run these in verbose mode (ksh -vx), both lines
expand to the same:


(Why the double equals in verbose mode?)

Thanks in advance,
Clyde

2. Bernoulli Box Drivers for AIX 1.2

3. Regular expression for 'AND'

4. assembler problems

5. Why "regular" expression?

6. Help needed with wierd FTP problem

7. How to translate regular expression into it's position in line?

8. Solaris Checkpoint firewall question

9. Problem using grep through the unix shell: doesn't accept a regular expression in filename

10. `pcre' Perl compatible regular expression library

11. Programming question - How to compare an array of char's with a regular expression?

12. I don't understand why this code isn't working

13. samba's nmdb isn't working - why?