Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #49617 > unrolled thread

Regular expression negative look-ahead

Started byJason Friedman <jsf80238@gmail.com>
First post2013-07-01 17:07 -0600
Last post2013-07-02 12:15 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Regular expression negative look-ahead Jason Friedman <jsf80238@gmail.com> - 2013-07-01 17:07 -0600
    Re: Regular expression negative look-ahead Neil Cerutti <neilc@norwich.edu> - 2013-07-02 12:15 +0000

#49617 — Regular expression negative look-ahead

FromJason Friedman <jsf80238@gmail.com>
Date2013-07-01 17:07 -0600
SubjectRegular expression negative look-ahead
Message-ID<mailman.4102.1372749590.3114.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

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.

[toc] | [next] | [standalone]


#49635

FromNeil Cerutti <neilc@norwich.edu>
Date2013-07-02 12:15 +0000
Message-ID<b3fuieF5rcbU1@mid.individual.net>
In reply to#49617
On 2013-07-01, Jason Friedman <jsf80238@gmail.com> wrote:
>
> 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

Use the "is not a word" character class on either end.

r"\WMY_TABLE\W"
r"\WYOUR_TABLE\W"

-- 
Neil Cerutti

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web