0

I have this Regex that mathes values with all same characters:

^(.)\1+$ is true for aaaaaa or 33333333 but not ssssssssR or even ssssssS

I need opposite one, but nothing with !? helped me.

Could someone hint what regex should be not to match values all-same character values?

Thanks in advance

Robert
  • 59
  • 2
  • 2
  • 7
  • It is `^(?!(.)\1+$).*` – Wiktor Stribiżew Apr 16 '20 at 21:25
  • Are you saying you wish the match to fail if the strings contains any character twice in a row, else the entire string is to be matched? – Cary Swoveland Apr 16 '20 at 22:00
  • Yes. This works. ^(?!(.)\1+$).* . Thanks everybody for help! – Robert Apr 16 '20 at 22:11
  • You answered "yes" to my question but your regex does not do that. For example, your regex matches `abbc`, but you say the match is to fail because `b` appears twice in a row. In fact, your regex matches every string having fewer than three characters and every string having three or more characters that are not all the same. If the problem is as I stated you need a regular expression such as the following: `^(?!.*(.)\1).*`. [Demo](https://regex101.com/r/z5ZPrd/1/). The negative lookahead reads, "the beginning of a line cannot be followed by 0+ chars then two instances of the same character". – Cary Swoveland Apr 16 '20 at 23:17
  • No, that was what I needed in fact. Thanks – Robert Apr 28 '20 at 17:50

0 Answers0