1

I was trying to write regular expression for string variable in swagger3(OAS).

The string can have multiple comma separated string. Each string's length can be between 5 and 15 and each character in a string can be either a-z or A-Z or 0-9.

I tried this one [a-zA-Z0-9]{5,15}. This one does not work as expected

For example Valid String eg

  1. 3OMYJF5V11MJL,3OMYJF5V11MOP
  2. 3OMYJF,3OMYJim,3OMYJF090

Invalid eg:

  1. ??
  2. 123
  3. 123456789098765432
Abdullah Imran
  • 259
  • 3
  • 13

1 Answers1

1

You could use:

^[a-zA-Z0-9]{5,15}(?:,[a-zA-Z0-9]{5,15})*$

Explanation

  • ^ Start of string
  • [a-zA-Z0-9]{5,15} Match 5-15 chars in the range a-zA-Z0-9
  • (?:,[a-zA-Z0-9]{5,15})* Optionally repeat , and again 5-15 chars
  • $ End of string

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70