minimalist regular expression

Discussion in 'Python' started by borges2003xx@yahoo.it, Aug 25, 2005.

  1. Guest

    Exists some tool, programs or some able to compute the minimal regular
    expression, namely ,taking a series of regular exoression, the minimal
    one that makes the same matching?
    thanx in advance
     
    , Aug 25, 2005
    #1
    1. Advertising

  2. Trent Mick Guest

    [ wrote]
    > Exists some tool, programs or some able to compute the minimal regular
    > expression, namely ,taking a series of regular exoression, the minimal
    > one that makes the same matching?


    def get_minimal_regex(*regexes):
    return ".*"

    :) Or, slightly less smart-ass-y:

    def get_not_really_minimal_regex(*regexes):
    return "(" + "|".join(regexes) + ")"

    Trent

    --
    Trent Mick
     
    Trent Mick, Aug 25, 2005
    #2
    1. Advertising

  3. Guest

    very nice
     
    , Aug 25, 2005
    #3
  4. John Bokma Guest

    John Bokma, Aug 25, 2005
    #4
  5. Guest

    the shortest description in regex way
     
    , Aug 26, 2005
    #5
  6. Paul Lalli Guest

    wrote:
    > Exists some tool, programs or some able to compute the minimal regular
    > expression, namely ,taking a series of regular exoression, the minimal
    > one that makes the same matching?
    > thanx in advance


    m//;

    it matches everything. Perhaps you need to better define your problem
    statement. Sample input, desired output...

    Paul Lalli
     
    Paul Lalli, Aug 26, 2005
    #6
  7. John Bokma Guest

    John Bokma, Aug 26, 2005
    #7
  8. Paul McGuire Guest

    Google for "optimized regexp" returns:
    http://laurent.riesterer.free.fr/regexp/make-regexp.html
    http://search.cpan.org/~dankogai/Regexp-Optimizer-0.15/

    There are several more links, but all appear to be written in languages
    other than Python. Perhaps you could port one of them.

    It also seems that a similar thread came up here recently, at least in
    the special form of converting a list of words to a single regexp. In
    general, this seems to be a difficult problem, not only to implement,
    but to test. At least the conversion of a list of words to a single
    regexp is easily tested against the input set, although as some of the
    other clever posters have noted, it is possible to create a regexp that
    is *too* matchable.

    -- Paul
     
    Paul McGuire, Aug 26, 2005
    #8
  9. Paul Lalli wrote:
    >
    > m//;
    >
    > it matches everything.


    Not in Perl it doesn't. :)
     
    Brian McCauley, Aug 26, 2005
    #9
  10. Paul Lalli Guest

    Brian McCauley wrote:
    > Paul Lalli wrote:
    > >
    > > m//;
    > >
    > > it matches everything.

    >
    > Not in Perl it doesn't. :)


    Sure it does.... provided you haven't tried matching anything else
    beforehand...

    Paul Lalli
     
    Paul Lalli, Aug 26, 2005
    #10
  11. Guest

    Whenever I ask a match in a string for(a{3,}b and match for (a{1,}, the
    first is implicit second: ab is implicit in a.*;automatically
     
    , Aug 26, 2005
    #11
    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. VSK
    Replies:
    2
    Views:
    2,332
  2. Uncle Bob (Robert C. Martin)

    Use Cases -- A minimalist's View

    Uncle Bob (Robert C. Martin), Jul 2, 2003, in forum: Java
    Replies:
    0
    Views:
    771
    Uncle Bob (Robert C. Martin)
    Jul 2, 2003
  3. Sam

    Minimalist executable

    Sam, Aug 15, 2003, in forum: C Programming
    Replies:
    3
    Views:
    550
    Mark McIntyre
    Aug 16, 2003
  4. Chris Thomasson

    Very Simple, Minimalist Technique For OOP in C...

    Chris Thomasson, Jun 21, 2007, in forum: C Programming
    Replies:
    10
    Views:
    688
    Johan Bengtsson
    Jun 24, 2007
  5. Replies:
    9
    Views:
    112
    Anno Siegel
    Aug 29, 2005
Loading...

Share This Page