Reverse RegEx or How to write a KeywordGenerator for a given

Discussion in 'Ruby' started by Mi Ni, Jan 31, 2008.

  1. Mi Ni

    Mi Ni Guest

    im new to ruby and have not the deep knowledge of all the possible ways
    to get a solution. but for to the sequence generator im very surprised
    of the clean short ruby solution..


    My Goal:
    write a parser for some patterns to generate some keywords from it.


    RegEx?
    i can have some regex to test some text, but is there a reverse way:
    generate from a given regex all possible mutations for it?


    what i found until now?
    i have found a sequence generator
    http://snippets.dzone.com/posts/show/3332
    witch i can give this pattern:

    x = [['abc'],['','-'],['def'],['','n'],['123','456']]

    and get this permutations/sequences:

    abcdef123
    abcdef456
    abcdefn123
    abcdefn456
    abc-def123
    abc-def456
    abc-defn123
    abc-defn456


    but i will not will not write this difficult arrays. i like a light
    pattern syntax to generate this arrays and permutations

    for instance for the given pattern:

    "abc-defn?[123|456]"

    i will generate this array:
    x = [['abc'],['','-'],['def'],['','n'],['123','456']]

    some rules:
    ? => means one or not
    | => mens OR
    [] => braces
    "-" => replace with this "-?"
    "ä" "ö" "ü" "ß" => automaticly goes to "[ä|ae]" or "[ü|ue]" or "[ö|oe]"
    or "[ss]"
    in combination with () and some $1 $2 i can generate some RegEx like
    substitutions
    with ${varname} i can include some predefined big patternlists


    i like also use recursive patterns:

    "[123[1|2]|45]" etc.


    Solutions?
    i can cut the strings with some string replace etc. but i think this is
    not the good ruby way.

    is a DSL parser/generator the right way for it? which one is the best
    for it (ParseTree/TreeTop/GhostWheel/

    can someone give me some routing directions where i can look for the
    best ruby way for my idea?
    --
    Posted via http://www.ruby-forum.com/.
     
    Mi Ni, Jan 31, 2008
    #1
    1. Advertising

  2. Mi Ni

    James Gray Guest

    On Jan 31, 2008, at 8:16 AM, Mi Ni wrote:

    > RegEx?
    > i can have some regex to test some text, but is there a reverse way:
    > generate from a given regex all possible mutations for it?


    Sure, for at least some subsets of regular expressions:

    http://www.rubyquiz.com/quiz143.html

    James Edward Gray II
     
    James Gray, Jan 31, 2008
    #2
    1. Advertising

  3. Mi Ni

    Mi Ni Guest

    Re: Reverse RegEx or How to write a KeywordGenerator for a g

    > Sure, for at least some subsets of regular expressions:
    >
    > http://www.rubyquiz.com/quiz143.html
    >
    > James Edward Gray II


    i look quick over the quiz. i think there some solutions for it :)
    i have to go deeper in the results.


    a solution for my german umlauts (äüöß) and "-" i can implement with
    string-replaces



    so i have to look also for:

    - a solution for my ? operator
    - a nested-syntax solution ... maybe this is in the quiz solutions...

    --
    Posted via http://www.ruby-forum.com/.
     
    Mi Ni, Jan 31, 2008
    #3
    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. Lord0
    Replies:
    1
    Views:
    601
    Thomas Weidenfeller
    Apr 19, 2006
  2. dogbite
    Replies:
    4
    Views:
    731
    osmium
    Oct 10, 2003
  3. chiara
    Replies:
    6
    Views:
    502
    Barry Schwarz
    Oct 6, 2005
  4. 2Barter.net
    Replies:
    0
    Views:
    399
    2Barter.net
    Dec 13, 2006
  5. Casey Hawthorne
    Replies:
    385
    Views:
    6,037
    ng2010
    Apr 4, 2010
Loading...

Share This Page