Home > front end >  Generating a String which matches given regex using random-Method of GENEREX
Generating a String which matches given regex using random-Method of GENEREX

Time:12-08

I am trying to generate a String which matches a given Regex using the random-Method of GENEREX.

Target: as defined in the random Method -> random(min, max), the String is supposed to have between a given min- and max-amount of characters.

Problem: the output is matching the defined regex BUT it contains only one character. So it doesn´t consider the defined min and max of the random-Method.

Code in question

generex= new Generex("[a-zA-Z]");
String output = generex.random(4,15);

Value of output at the moment: "P" (f.E.)

Im Expecting something like output: "WorksFine"

CodePudding user response:

I think the problem is with your Regex. It currently is "[a-zA-Z]". So it is only one character. If you want multiple letters you need to add a " ". So it should be:

generex= new Generex("[a-zA-Z] ");

  • Related