Regular expression negative look-ahead

Discussion in 'Python' started by Jason Friedman, Jul 2, 2013.

  1. 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.
     
    Jason Friedman, Jul 2, 2013
    #1
    1. Advertisements

  2. Jason Friedman

    Neil Cerutti Guest

    On 2013-07-01, Jason Friedman <> 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
     
    Neil Cerutti, Jul 2, 2013
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,657
  2. Prabh
    Replies:
    1
    Views:
    528
    Wendy S
    Sep 11, 2003
  3. Aubrey Hutchison

    GO AHEAD -MAKE ME LOOK DUMB- Please

    Aubrey Hutchison, Dec 31, 2003, in forum: Python
    Replies:
    4
    Views:
    412
    Aubrey Hutchison
    Dec 31, 2003
  4. inhahe
    Replies:
    3
    Views:
    2,984
    Diez B. Roggisch
    Jan 28, 2005
  5. Neil Cerutti

    An iterator with look-ahead

    Neil Cerutti, Jan 10, 2007, in forum: Python
    Replies:
    5
    Views:
    863
    Paddy
    Jan 10, 2007
  6. Simon Fairey

    Negative Look Ahead question?

    Simon Fairey, Jun 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    215
  7. Replies:
    4
    Views:
    392
  8. cibalo
    Replies:
    2
    Views:
    267
    Rainer Weikusat
    May 23, 2013
Loading...