[gull] expressions régulières sous php
patrick jayet
jayetp at student.ethz.ch
Sun Dec 5 01:08:01 CET 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Bonsoir à tous!
Petite question sur les expressions régulières sous php. J'ai un petit
problème avec la "greediness" du processing. Voici le code:
$str = "<foo>hello there</foo>\n<foo>go there</foo>\n";
echo $str;
<foo>hello there</foo>
<foo>go there</foo>
$str1 = preg_replace("%<foo.*hello.*</foo>%Us","replaced1", $str);
echo $str1;
replaced1
<foo>go there</foo>
$str2 = preg_replace("%<foo.*go.*</foo>%Us","replaced2", $str);
echo $str2;
replaced2
Je ne comprend pas pourquoi j'obtiens 2 choses différentes suivant que
je fait un match du 1e tag <foo></foo> ou du 2e. L'option U est sensé
désactiver le greediness (ce qui est bien le cas lors de la 1e
substitution). Mais pour la 2e, ça ne semble pas marcher.
Quelqu'un aurait-il une idée?
Bon week-end!
Pat
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFBslDtDdcPKzlCXVMRAkuZAJ95fVuZyBD5x0K76Lhibz/VpsiDYACgiJ87
6fCOONsUKhlCzERQ/syO8us=
=lkzx
-----END PGP SIGNATURE-----
More information about the gull
mailing list