<br><br><div class="gmail_quote">2008/11/27 r0g <span dir="ltr"><<a href="http://aioe.org">aioe.org</a>@<a href="http://technicalbloke.com">technicalbloke.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
<br>
I want to use a regex to match a string "poo" but not "poo\n" or<br>
"poo"+chr(13) or "poo"+chr(10) or "poo"+chr(10)+chr(13)<br>
<br>
...</blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Thanks,<br>
<br>
<br>
Roger.<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote><div></div><div>Hi,</div><div>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.:</div>
<div></div><div>>>> re.findall(r'(?ms)\b\w+\b', 'to match a string poo1 but not poo2\n poo3\rpoo4\npoo5\n\rqwer')<br>['to', 'match', 'a', 'string', 'poo1', 'but', 'not', 'poo2', 'poo3', 'poo4', 'poo5', 'qwer']<br>
>>> re.findall(r'(?ms)\b\w+\b(?![\r\n])', 'to match a string poo1 but not poo2\n poo3\rpoo4\npoo5\n\rqwer')<br>['to', 'match', 'a', 'string', 'poo1', 'but', 'not', 'qwer']<br>
>>> <br></div><div></div><div>The pattern is a bit modified - here all "words" should be matched (in the second example excluding the ones followed by \r or \n).</div><div></div><div>hth</div><div> Vlasta</div>
<div></div></div>