Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Regular expression negative look-ahead

Reply
Thread Tools

Regular expression negative look-ahead

 
 
Jason Friedman
Guest
Posts: n/a
 
      07-01-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.

 
Reply With Quote
 
 
 
 
Neil Cerutti
Guest
Posts: n/a
 
      07-02-2013
On 2013-07-01, Jason Friedman <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Regular expression negative look-ahead Ian Kelly Python 0 07-02-2013 05:44 AM
Re: Regular expression negative look-ahead Jason Friedman Python 0 07-02-2013 02:27 AM
Problem: perl negative look-ahead assertion in multi-line mode cibalo Perl Misc 2 05-23-2013 02:33 PM
Why do look-ahead and look-behind have to be fixed-width patterns? inhahe Python 3 01-28-2005 12:50 PM
Negative Look Ahead question? Simon Fairey Perl Misc 3 06-11-2004 03:45 PM



Advertisments