2008/11/27 r0g <[EMAIL PROTECTED]> > Hi, > > I want to use a regex to match a string "poo" but not "poo\n" or > "poo"+chr(13) or "poo"+chr(10) or "poo"+chr(10)+chr(13) > > ...
> Thanks, > > > Roger. > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, if I understand correctly, that you want to exclude matches of strings followed by certain characters, you may use the negative lookahead assertion (you can consult the details in the references you mentioned); cf.: >>> re.findall(r'(?ms)\b\w+\b', 'to match a string poo1 but not poo2\n poo3\rpoo4\npoo5\n\rqwer') ['to', 'match', 'a', 'string', 'poo1', 'but', 'not', 'poo2', 'poo3', 'poo4', 'poo5', 'qwer'] >>> re.findall(r'(?ms)\b\w+\b(?![\r\n])', 'to match a string poo1 but not poo2\n poo3\rpoo4\npoo5\n\rqwer') ['to', 'match', 'a', 'string', 'poo1', 'but', 'not', 'qwer'] >>> The pattern is a bit modified - here all "words" should be matched (in the second example excluding the ones followed by \r or \n). hth Vlasta
-- http://mail.python.org/mailman/listinfo/python-list