2

次のような数値文字列がいくつかあります。

0000000
0000011
0000012

パターンが次のようなものであることを検証したい:

AAAAABC

ここでABCはすべて異なる数字です。したがって、この例では、のみ0000012が一致する必要があります。

これまでの私の正規表現は です(\d)\1\1\1\1\d\dが、数字が異なることを確認していません。私は何をする必要がありますか?

4

1 に答える 1

3

私はあなたが欲しいと思います

(\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で参照してください。

于 2013-04-05T12:37:04.903 に答える