Le 13/07/2008 17:49, SAM a écrit :
> >
> > sujet.replace('/(?<=[[,])(null,)*null[],]/',
> > function(match) {
> > count = strlen(match)/5;
> > last = match.substring(strlen(match)-1);
> > return '#' + count + last;
> > });
> >
> > (non testé)
>
> à mon idée ce devrait être plus proche de :
>
> function dorepnull(sujet) {
> sujet = sujet.replace(/(?<=[[,])(null,)*null[],]/,
> function(match) {
> return '#' + match.length/5 + match.substring(match.length-1);
> });
> return sujet;
> }
> alert(dorepnull($b));
Oui, tu as bien raison, même s'il restait encore au moins un PHP-isme.
> Bon ... ça marche pô :-(
>
> Erreur : invalid quantifier ?<=[[,])(null,)*null[],]
> Code Source :
> sujet = sujet.replace(/(?<=[[,])(null,)*null[],]/,
Rhazut, je pensais pourtant que les assertions arrières faisaient partie
du tronc commun Perl/PCRE. Autre problème, il ne comprend pas non plus
[],] alors que [\],] marche bien.
Bref, j'ai testé ceci, et ça marche :
------------------------------------------------------------------------
function dorepnull(sujet) {
return sujet.replace(/[[,](null,)*null[\],]/g,
function(match) {
return match.substring(0,1) + '#' + (match.length-1)/5
+ match.substring(match.length-1);
});
}
------------------------------------------------------------------------
sujet = '[null,null,null,null,null]';
alert(sujet + "\n" + dorepnull(sujet));
sujet = '[a,null,b,null,null,c,null,d]';
alert(sujet + "\n" + dorepnull(sujet));
sujet = '[nullard,annulle,null,tronull,"null",null,nul]';
alert(sujet + "\n" + dorepnull(sujet));
------------------------------------------------------------------------