Home > Mobile >  Generate strings larger than and lesser than
Generate strings larger than and lesser than

Time:11-03

I need to test my method which is validate input Strings larger and lesser than. I already achieved something like that:

//given
var generex = new Generex("[a-zA-Z]{3,100}");
patientDtoIn.setFirstName(generex.random());

This regex generate Strings larger than 3 and lesser than 100. Including this 2 numbers too. Now I need the opposite. "Lesser than 3 and larger than 100" excluding those 2 numbers. Could someone help me with that?

CodePudding user response:

You can use this regex:

^(?:[a-zA-Z]{1,2}|[a-zA-Z]{101,})$

Pattern explanation: ^ - match beginning of the string

(?:...) - non capturing group (used to group pattern)

[a-zA-Z]{1,2} - match pattern 1 or 2 times

| - alternation operator

[a-zA-Z]{101,} - match pattern 101 or more times

$ - match end of the string

Regex demo

  • Related