[clug] Help with a python regexp?

Michael Cohen scudette at gmail.com
Sun Feb 22 01:37:52 GMT 2009

This is where something like


rings so true.... Of course the obvious, maintainable, readable, and
almost certainly faster change would be to modify the python code to
do what you want.

Often people try to do stuff with regex which is way too ambitious -
like try to match URLs in HTML, tags etc. It might appear to work for
most cases you throw at it, but it really needs a proper parser to do
this. A fact which you find out too late because your regex failed to
match in edge cases. In my experience when a regex gets too complex
you are probably using the wrong tool.


On Sun, Feb 22, 2009 at 12:29 PM, Jeremy Kerr <jk at ozlabs.org> wrote:
> Hi Brad,
>> So how to I match a line containing "warning:", as long as it doesn't
>> start with "exchange.idl"?
> You want the (?!...) grouping operator. From 'pydoc re':
>  (?!...)  Matches if ... doesn't match next.
> For example:
>  warning_re = re.compile('(?!exchange.idl).*warning[: ].*')
> Cheers,
> Jeremy
> --
> linux mailing list
> linux at lists.samba.org
> https://lists.samba.org/mailman/listinfo/linux

More information about the linux mailing list