Re: regular expression and not form



caiqian@xxxxxxxxx wrote:
Hi,

Xicheng Jia wrote:
caiqian@xxxxxxxxx wrote:
Hi,

How can I express "match any string except 'ABC'" in regular
expression?


If you can use tools supporting Perl-compatible regex, like Perl,
python, Ruby, then, the regex can be written as:

^(?!.*ABC)

The following command prints all lines which dont contain the string
"ABC" in *myfile*

perl -ne 'print if/^(?!.*ABC)/' myfile

Xicheng

Works fine. I am still wondering if there is a way to do the following
in Bash use =~, and my grep does not support -P (perl regular
expression) yet.

Qian

grep -v ABC

:-)

Xicheng

.



Relevant Pages

  • Re: regular expression and not form
    ... How can I express "match any string except 'ABC'" in regular ... If you can use tools supporting Perl-compatible regex, like Perl, ... The following command prints all lines which dont contain the string ...
    (comp.unix.shell)
  • Re: escape sequence for tab not working
    ... This sets $this_str to "abc", followed by a literal tab, followed by ... So echo doesn't get to see ... Here Perl prints the value without shell intervention. ...
    (comp.lang.perl.misc)
  • Re: What do you need to have to be considered a Master at Perl?
    ... Someone who understands the Chomsky hierarchy, ... I don't think perl actually existed back then. ... "I've learnt how to match balanced parentheses with regular expressions." ... I don't care if perl regular expressions are or aren't kosher. ...
    (comp.lang.perl.misc)
  • RE: perl question - unused variables
    ... declare a variable called '$nothing' in a script on working on now, ... Subject: RE: perl question - unused variables ... $abc; and using strict and -w, I do not get any warning. ...
    (perl.beginners)
  • Re: Cant get desired o/p with this code
    ... Thanks a lot Chas for your your Help. ... But where you are storing the exit status of the use command. ... Suppose I want to check that perl is ... but when I am changing the name from perl to abc(which doesn't exists) then ...
    (perl.beginners)