Generating strings that are matched by a regex
-
Folks, For bizarre reasons, I need to be able to generate random strings that will be matched by a given regex. i.e. given [a-z][a-z1-9][qrst] I want an algorithm that will generate abs z9q dvt et cetera... Anyone hear of anything similar? Or maybe you know a simple regex parser that I cannibalize? (C# preferable, or a C related language) Thanks, Brett DTrent
-
Folks, For bizarre reasons, I need to be able to generate random strings that will be matched by a given regex. i.e. given [a-z][a-z1-9][qrst] I want an algorithm that will generate abs z9q dvt et cetera... Anyone hear of anything similar? Or maybe you know a simple regex parser that I cannibalize? (C# preferable, or a C related language) Thanks, Brett DTrent
It's obviously pretty easy to code one for each individual regular expression by hand, but something that generates a random string for ANY given regular expression seems like it would be fairly complicated. I'm pretty sure there's nothing in the base classes for this. It would definitely have to understand the regular expression syntax you're using. How would you handle something like: [a-z]* That means zero to "infinite" lower case letters basically. Would your random generator have an upper limit on cases like that? Would you want zero's to occur more often than other numbers? I wish I could help more, but I've never heard of anyone doing this (haven't really searched or anything though). Let me know how it turns out.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins -
Folks, For bizarre reasons, I need to be able to generate random strings that will be matched by a given regex. i.e. given [a-z][a-z1-9][qrst] I want an algorithm that will generate abs z9q dvt et cetera... Anyone hear of anything similar? Or maybe you know a simple regex parser that I cannibalize? (C# preferable, or a C related language) Thanks, Brett DTrent
I have a simple C# Regex lib designed for a lexer, rather than normal RE. I'll send you the code and if you can use it, i would dearly love to have it :) Obviously you would be credited (just place a gpl on your source). Reply to this message so I grab your email :) leppie::AllocCPArticle("Zee blog");
Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it. -
I have a simple C# Regex lib designed for a lexer, rather than normal RE. I'll send you the code and if you can use it, i would dearly love to have it :) Obviously you would be credited (just place a gpl on your source). Reply to this message so I grab your email :) leppie::AllocCPArticle("Zee blog");
Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.