Utility to locate errors in regular expressions

Discussion in 'Python' started by Malte Forkel, May 24, 2013.

  1. Malte Forkel

    Malte Forkel Guest

    Finding out why a regular expression does not match a given string can
    very tedious. I would like to write a utility that identifies the
    sub-expression causing the non-match. My idea is to use a parser to
    create a tree representing the complete regular expression. Then I could
    simplify the expression by dropping sub-expressions one by one from
    right to left and from bottom to top until the remaining regex matches.
    The last sub-expression dropped should be (part of) the problem.

    As a first step, I am looking for a parser for Python regular
    expressions, or a Python regex grammar to create a parser from.

    But may be my idea is flawed? Or a similar (or better) tools already
    exists? Any advice will be highly appreciated!

    Malte
     
    Malte Forkel, May 24, 2013
    #1
    1. Advertising

  2. Malte Forkel

    Roy Smith Guest

    In article <>,
    Malte Forkel <> wrote:

    > Finding out why a regular expression does not match a given string can
    > very tedious. I would like to write a utility that identifies the
    > sub-expression causing the non-match. My idea is to use a parser to
    > create a tree representing the complete regular expression. Then I could
    > simplify the expression by dropping sub-expressions one by one from
    > right to left and from bottom to top until the remaining regex matches.
    > The last sub-expression dropped should be (part of) the problem.
    >
    > As a first step, I am looking for a parser for Python regular
    > expressions, or a Python regex grammar to create a parser from.
    >
    > But may be my idea is flawed? Or a similar (or better) tools already
    > exists? Any advice will be highly appreciated!


    I think this would be a really cool tool. The debugging process I've
    always used is essentially what you describe. I start try progressively
    shorter sub-patterns until I get a match, then try to incrementally add
    back little bits of the original pattern until it no longer matches.
    With luck, the problem will become obvious at that point.

    Having a tool which automated this would be really useful.

    Of course, most of Python user community are wimps and shy away from big
    hairy regexes [ducking and running].
     
    Roy Smith, May 24, 2013
    #2
    1. Advertising

  3. Malte Forkel

    Neil Cerutti Guest

    On 2013-05-24, Roy Smith <> wrote:
    > Of course, most of Python user community are wimps and shy away
    > from big hairy regexes [ducking and running].


    I prefer the simple, lumbering regular expressions like those in
    the original Night of the Regular Expressions. The fast, powerful
    ones from programs like the remake of Dawn of the GREP, just
    aren't as scary.

    --
    Neil Cerutti
     
    Neil Cerutti, May 24, 2013
    #3
  4. Malte Forkel

    rusi Guest

    On May 24, 5:58 pm, Malte Forkel <> wrote:
    > Finding out why a regular expression does not match a given string can
    > very tedious. I would like to write a utility that identifies the
    > sub-expression causing the non-match. My idea is to use a parser to
    > create a tree representing the complete regular expression. Then I could
    > simplify the expression by dropping sub-expressions one by one from
    > right to left and from bottom to top until the remaining regex matches.
    > The last sub-expression dropped should be (part of) the problem.
    >
    > As a first step, I am looking for a parser for Python regular
    > expressions, or a Python regex grammar to create a parser from.
    >
    > But may be my idea is flawed? Or a similar (or better) tools already
    > exists? Any advice will be highly appreciated!
    >
    > Malte




    python-specific: http://kodos.sourceforge.net/
    Online: http://gskinner.com/RegExr/
    emacs-specific: re-builder and regex-tool http://bc.tech.coop/blog/071103.html
     
    rusi, May 24, 2013
    #4
    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. Jay Douglas
    Replies:
    0
    Views:
    610
    Jay Douglas
    Aug 15, 2003
  2. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    964
    Mark Goldin
    Jan 17, 2004
  3. Atul Dongargaonkar
    Replies:
    2
    Views:
    98
    Martin DeMello
    Oct 6, 2010
  4. Devin Jeanpierre
    Replies:
    1
    Views:
    88
    Roy Smith
    May 24, 2013
  5. Noman Shapiro
    Replies:
    0
    Views:
    235
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page