0

How I validate not allow repeat two dash (--) after specific string 0-1P:

^\w0-1P(?:([\w-])

Example:

10-1P-8 will valid

10-1Pabc-- will invalid (because has twodash)

z0-1PDTD--SDSA-- will invalid (because has twodash repeat twice time)

Link my regular expression but it valid threedash(---), how can i fix it.

Giau Huynh
  • 300
  • 3
  • 15

1 Answers1

2

You can use a negative lookahead assertion as this one:

^\w0-1P(?!.*--)[\w-]*$

Updated RegEx Demo

(?!.*--) is negative lookahead that will fail the match if we have -- anywhere after matching \w0-1P at the start of input.

anubhava
  • 761,203
  • 64
  • 569
  • 643