/ / Génération d’une expression régulière - regex, nombres

Générer une expression régulière - regex, nombres

Quelqu'un peut-il m'aider à créer une expression rationnelle vérifiant que le nombre comporte 2 et 4 répétitions de chiffres, comme pour vérifier si cette expression est non? 5555122.

Je veux savoir par expression régulière qu'il y a répétition du quatrième double.

Réponses:

0 pour la réponse № 1

Vous pouvez utiliser la référence arrière

(d)1{3}

Cela vérifierait la répétition de 4 chiffres


0 pour la réponse № 2

Essaye ça

(d)(?:1{3}|1)

explication

"
(           # Match the regular expression below and capture its match into backreference number 1
\d          # Match a single digit 0..9
)
(?:         # Match the regular expression below
# Match either the regular expression below (attempting the next alternative only if this one fails)
\1          # Match the same text as most recently matched by capturing group number 1
{3}         # Exactly 3 times
|           # Or match regular expression number 2 below (the entire group fails if this one fails to match)
\1          # Match the same text as most recently matched by capturing group number 1
)
"

MODIFIER

Motif dans (?:1{3}|1), besoin de plus d'attention. Si c'est comme (?:1|1{3}) cela ne correspondrait pas à ce qui était prévu. Parce que, The Regex-Directed Engine Always Returns the Leftmost Match.