0

I need to generate a regular expression to validate that the string does not start with 5 digits.

NOT VALID: 12345testing123asd

VALID: 1234testing1234
testing12345
testing

I tried to get the first five chars ^.{0,5} but I do not know hot to add the restriction of \D to those first 5 chars

Also, I tried with this [^0-9][^0-9][^0-9][^0-9][^0-9] but I do not know how to do to include the strings that starts with 4 or less numbers

Could you please help me with this? I am a rookie :(

1 Answers1

0

If your RegExp flavor of choice supports negative lookaheads, this pattern will match if the string is valid (does not start with 5 or more consecutive digits):

^(?!\d{5,})

Regex101

Matches:

  • 1234testing1234
  • testing12345
  • testing

Does not match:

  • 12345testing123asd
esqew
  • 42,425
  • 27
  • 92
  • 132