Reverse RegEx or How to write a KeywordGenerator for a given

M

Mi Ni

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?
 
M

Mi Ni

Sure, for at least some subsets of regular expressions:

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top