-1

I've tried to make a regular expression that match anything except if contains a 11 digits like 12345678910 so don't match anything what i have tried

[^\d{11}]

but {11} doesn't work with \d expression so what i have to do ?

Karim Mamdouh
  • 55
  • 1
  • 7
  • `[...]` defines a character class, inside which most meta-character lose their special meaning. Here your class just matches any character but `d`, `{`, `1` or `}` – Aaron Oct 03 '17 at 16:33
  • @gil.fernandes he doesn't want to match if it has 11 digits, 8,9,10 digits should do – marvel308 Oct 03 '17 at 16:35

3 Answers3

1

you can use the regex

^(?!.*\d{11}).*$

see the regex101 demo

marvel308
  • 10,288
  • 1
  • 21
  • 32
  • Note that not all regex engines support lookarounds (exemple : neither POSIX's ERE nor BRE do) ; the answer's still good, I just want to save OP some confusion if it doesn't work for him :) – Aaron Oct 03 '17 at 16:43
0

It's not a very good task for regex to solve actually, because you have to describe every string that doesn't contain 11 consecutive digits.

If possible, I suggest matching a string that does contain 11 consecutive digits, then inverting the success of that match with the language or tool from which you execute this regex.

Depending on your regex flavour, you might also be able to use a negative lookahead such as presented in other answers.

Aaron
  • 24,009
  • 2
  • 33
  • 57
0

This seemed to work for me using a negative look around:

/^((?!\d{11}).)*$/gm

Dean
  • 396
  • 3
  • 10
  • Note that not all regex engines support lookarounds (exemple : neither POSIX's ERE nor BRE do) ; the answer's still good, I just want to save OP some confusion if it doesn't work for him :) – Aaron Oct 03 '17 at 16:43
  • look it'll match the next line even if contain 11 digits https://imgur.com/6GepkHL – Karim Mamdouh Oct 03 '17 at 16:57