This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
will you need to dynamically generated the output based on user supplied regex input? or will it ALWAYS be a-zA-Z?
Basically, you need to determine what the range of values is. a-z is 26 values, and then A-Z is another 26. That means you need to generate a number from 1-52. you then need to map your numbers to your output values.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Jun 28, 2008
or will it ALWAYS be a-zA-Z?
yes, this is what I want.
In perl, does Java has a similar method like perls "random_regex" ? Should I use perl within java? Is that possible?
So, you have the fixed regular expression "[a-zA-Z]+" and you want to generate a random word that matches it? That's easy: generate a random number (>= 1) of lower-case and upper-case letters and concatenate them. No need to bother with difficult things such as trying to use Perl from Java (which is not easy). Java has no built-in method like Perl's random_regex.
Or do you want to be able to do this for arbitrary regular expressions?