[RESOLU] RegEx [sous-masques uniques] Bug ?

Eléphant du PHP | 65 Messages

27 juil. 2016, 21:45

Bonjour à tous,
Je suis sous PHP 7.0.8 et je rencontre un problème que j'ai du mal a expliquer.
Essayez ceci :

Code : Tout sélectionner

$string = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<1544><45>?aaaaaaaaaaaaaaaaa'; preg_match('#(\D+|<\d+>)*[!?]#', $string, $matches); var_dump($matches); /* array (size=2) 0 => string 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<1544><45>?' (length=41) 1 => string '<45>' (length=4) */ /* Je rajoute deux ou trois « a » après le « ? » (un seul suffit) */ $string = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<1544><45>?aaaaaaaaaaaaaaaaaaaaa'; preg_match('#(\D+|<\d+>)*[!?]#', $string, $matches); var_dump($matches); /* array (size=0) empty Pourquoi empty ? */ /* Alors que */ preg_match('#((?>\D+)|<\d+>)*[!?]#', $string, $matches); var_dump($matches); /* array (size=2) 0 => string '<1544><45>?' (length=11) 1 => string '<45>' (length=4) */
Est-ce un bug ?

PS : Désolé pour les 3 edit je me suis embrouillé.

Mammouth du PHP | 2703 Messages

27 juil. 2016, 22:02

https://regex101.com/r/tB6zM6/1 retourne :
"Catastrophic backtracking
Catastrophic backtracking has been detected and the execution of your expression has been halted. "

il faut essayer de faire les choses différemment.