Re: Regular expression negative look-ahead

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

  1. Found this:
    http://stackoverflow.com/questions/13871833/negative-lookahead-assertion-not-working-in-python
    ..

    This pattern seems to work:
    pattern = re.compile(r"^(?!.*(CTL|DEL|RUN))")

    But I am not sure why.


    On Mon, Jul 1, 2013 at 5:07 PM, 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
    >
    > 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. Advertising

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. Simon Fairey

    Negative Look Ahead question?

    Simon Fairey, Jun 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    143
  2. Ian Kelly
    Replies:
    0
    Views:
    98
    Ian Kelly
    Jul 2, 2013
  3. Jason Friedman

    Regular expression negative look-ahead

    Jason Friedman, Jul 2, 2013, in forum: Python
    Replies:
    1
    Views:
    71
    Neil Cerutti
    Jul 2, 2013
  4. Jason Friedman

    Re: Regular expression negative look-ahead

    Jason Friedman, Jul 4, 2013, in forum: Python
    Replies:
    0
    Views:
    74
    Jason Friedman
    Jul 4, 2013
  5. Jason Friedman

    Re: Regular expression negative look-ahead

    Jason Friedman, Jul 4, 2013, in forum: Python
    Replies:
    0
    Views:
    76
    Jason Friedman
    Jul 4, 2013
Loading...

Share This Page