public static String randomRegexpishString(Random r,int maxLength){
  final StringBuilder regexp=new StringBuilder(maxLength);
  for (int i=nextInt(r,0,maxLength); i > 0; i--) {
    if (r.nextBoolean()) {
      regexp.append((char)RandomNumbers.randomIntBetween(r,'a','z'));
    }
 else {
      regexp.append(RandomPicks.randomFrom(r,ops));
    }
  }
  return regexp.toString();
}

public static String randomRegexpishString ( Random r , int maxLength ) { final StringBuilder regexp = new StringBuilder ( maxLength ) ; for ( int i = nextInt ( r , 0 , maxLength ) ; i > 0 ; i -- ) { if ( r . nextBoolean ( ) ) { regexp . append ( ( char ) RandomNumbers . randomIntBetween ( r , 'a' , 'z' ) ) ; } else { regexp . append ( RandomPicks . randomFrom ( r , ops ) ) ; } } return regexp . toString ( ) ; }
returns a string thats " regexpish " ( contains lots of operators typically found in regular expressions ) if you call this enough times , you might get a valid regex ! < p > note : to avoid practically endless backtracking patterns we replace asterisk and plus operators with bounded repetitions . see lucene - 4111 for more info .
