次のような数値文字列がいくつかあります。
0000000
0000011
0000012
パターンが次のようなものであることを検証したい:
AAAAABC
ここでA
、B
とC
はすべて異なる数字です。したがって、この例では、のみ0000012
が一致する必要があります。
これまでの私の正規表現は です(\d)\1\1\1\1\d\d
が、数字が異なることを確認していません。私は何をする必要がありますか?
私はあなたが欲しいと思います
(\d)\1{4}(?!\1)(\d)(?!\1|\2)\d
説明:
(\d) # Match a digit, capture in group 1
\1{4} # Match the same digit as before four times
(?!\1) # Assert that the next character is not the same digit as before
(\d) # Match another digit, capture in group 2
(?!\1|\2) # Assert the next character is different from both previous digits
\d # Match another digit.
regex101で参照してください。