Opposite result of a regular expression
-
28-06-2021 - |
Pergunta
I have this regex
^(\d+)/\1$
that matches strings like
1/1
2/2
5/5
I want to get the inverse result of this regex. I browsed the net and stack overflow and found that
^((?!(\d+)/\1.).)*$
should do the trick, but it doesn't.
Could anyone point me into the right direction?
Solução
/^(\d+)\/(?!\1$)\d+$/
This will match 2/3
or 1/10
, but not 1/1
and 2/2
, et cetera. In other words, it will match only when the first part of the fraction is different from the second part.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow