Regular expression negative look-ahead

Jason Friedman jsf80238 at gmail.com
Mon Jul 1 19:07:57 EDT 2013


I have table names in this form:
MY_TABLE
MY_TABLE_CTL
MY_TABLE_DEL
MY_TABLE_RUN
YOUR_TABLE
YOUR_TABLE_CTL
YOUR_TABLE_DEL
YOUR_TABLE_RUN

I am trying to create a regular expression that will return true for only
these tables:
MY_TABLE
YOUR_TABLE

I tried these:
pattern = re.compile(r"_(?!(CTL|DEL|RUN))")
pattern = re.compile(r"\w+(?!(CTL|DEL|RUN))")
pattern = re.compile(r"(?!(CTL|DEL|RUN)$)")

But, both match.
I do not need to capture anything.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130701/26bb2290/attachment.html>


More information about the Python-list mailing list