Re: regexp match string with word1 and not word2



Flyzone wrote:
Hello,
i have again problem with regexp :-P
I need to match all lines that contain one word but not contain
another.
Like to do "grep one | grep -v two:"
The syntax of the string is:
(any printable char)two:(any printable char)one(any printable char)
Example:
Apr 30 00:00:09 v890neg0 two: [ID 702911 daemon.one] findings:
blablabla

I tried with:
.*[^t][^w][^o].*one.*
but is not working, the string is always match and in other tries
using "less logic" i get always some different match :-(

P.S: i can't have more re.search, so i just need ONE regexp


The P.S: suggests homework, but this can't be homework because python regex won't do this, so your teacher gets an F if its homework. You require a negative look-behind assertion of variable length--not possible in python regex. You will have to use something else--or maybe you don't understand the homework problem.

James
.



Relevant Pages

  • Re: Regexp, ***= and subexpressions
    ... specified that the user's input be treated as a literal string rather than ... -exact] in cases where regexp isn't required:P ... Seems to be that regexp can't match word boundaries at "non-word" ... But now Earth has rotated and I can get back to sleep. ...
    (comp.lang.tcl)
  • Re: Regexp: Case-insensitive matching | N factorial
    ... a regexp component that matches a string of letters, ... Will match the string 'cat' anywhere it appears regardless of case. ... Javascript regular expressions have an alternative operator '|' (kind ...
    (comp.lang.javascript)
  • Re: How to get the "longest possible" match with Pythons RE module?
    ... Under most "NFA" implementation, such a regexp is ... searching a very long string that happens not to contain any matches. ... under many implementations it's very easy to end ... double-quote character at each end, and backslash escapes, ...
    (comp.lang.python)
  • Re: String search vs regexp search
    ... of occurences using string & regexp. ... I wrote the code for the regexp search as well as the function ... How long is the substring? ...
    (comp.lang.python)
  • Regular Expression Help
    ... I was wondering if someone could tell me where I'm going wrong with my regular expression. ... I'm trying to write a regexp that identifies whether a string contains a correctly-formatted currency amount. ... print str + " is not a match" ...
    (comp.lang.python)