Home > Software design >  Regular Expression: Opposite of specific length of numbers
Regular Expression: Opposite of specific length of numbers

Time:02-18

According to the title. I'm looking for a regular expression to match the unspecified length of numbers (any length except 10).

It no't work:

(?!\d{10}$)

Best Regards.

CodePudding user response:

Currently your pattern is an unanchored negative lookahead assertion that fires at every position.

What you can do is anchor it at the start of the string, and match the digits until the end of the string:

^(?!\d{10}$)\d $

See a regex demo.

Or alternatively match either 1-9 or 11 or more digits

^(?:\d{1,9}|\d{11,})$
  • Related