Tiens, il semblerait que ce soit possible en JavaScript aussi depuis la
version 1.3 :
http://developer.mozilla.org/fr/docs/R%C3%A9f%C3%A9rence_de_JavaScript_1.5_Core:Objets_globaux:String:replace#Exemple_:_utilisation_d.27une_fonction_inline_modifiant_les_caract.C3.A8res_trouv.C3.A9s
Donc :
sujet.replace('/(?<=[[,])(null,)*null[],]/',
function(match) {
count = strlen(match)/5;
last = match.substring(strlen(match)-1);
return '#' + count + last;
});
(non testé)
Je n'ai pas le temps de rappeler le contexte pour faire suivre dans
fr.comp.lang.javascript, mais ne pas hésiter à le faire s'il y a besoin
de poursuivre les recherches dans ce langage.
Tiens, il semblerait que ce soit possible en JavaScript aussi depuis la
version 1.3 :
http://developer.mozilla.org/fr/docs/R%C3%A9f%C3%A9rence_de_JavaScript_1.5_Core:Objets_globaux:String:replace#Exemple_:_utilisation_d.27une_fonction_inline_modifiant_les_caract.C3.A8res_trouv.C3.A9s
Donc :
sujet.replace('/(?<=[[,])(null,)*null[],]/',
function(match) {
count = strlen(match)/5;
last = match.substring(strlen(match)-1);
return '#' + count + last;
});
(non testé)
Je n'ai pas le temps de rappeler le contexte pour faire suivre dans
fr.comp.lang.javascript, mais ne pas hésiter à le faire s'il y a besoin
de poursuivre les recherches dans ce langage.
Tiens, il semblerait que ce soit possible en JavaScript aussi depuis la
version 1.3 :
http://developer.mozilla.org/fr/docs/R%C3%A9f%C3%A9rence_de_JavaScript_1.5_Core:Objets_globaux:String:replace#Exemple_:_utilisation_d.27une_fonction_inline_modifiant_les_caract.C3.A8res_trouv.C3.A9s
Donc :
sujet.replace('/(?<=[[,])(null,)*null[],]/',
function(match) {
count = strlen(match)/5;
last = match.substring(strlen(match)-1);
return '#' + count + last;
});
(non testé)
Je n'ai pas le temps de rappeler le contexte pour faire suivre dans
fr.comp.lang.javascript, mais ne pas hésiter à le faire s'il y a besoin
de poursuivre les recherches dans ce langage.
>
> 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));
Bon ... ça marche pô :-(
Erreur : invalid quantifier ?<=[[,])(null,)*null[],]
Code Source :
sujet = sujet.replace(/(?<=[[,])(null,)*null[],]/,
>
> 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));
Bon ... ça marche pô :-(
Erreur : invalid quantifier ?<=[[,])(null,)*null[],]
Code Source :
sujet = sujet.replace(/(?<=[[,])(null,)*null[],]/,
>
> 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));
Bon ... ça marche pô :-(
Erreur : invalid quantifier ?<=[[,])(null,)*null[],]
Code Source :
sujet = sujet.replace(/(?<=[[,])(null,)*null[],]/,
Résumé depuis f.c.l.php :
======== Etienne SOBOLE a écrit :
>
> Ça donne :
>
> var expr = /(null,)+/
> var tRes = expr.exec(sDossier);
> while (tRes)
> {
> var sDossier = sDossier.replace(expr,
"@N" + (tRes[0].length / tRes[1].length) + "@");
> var tRes = expr.exec(sDossier);
> }
>
> et ca remplace une liste de null, par @Nx@
> où x est le nombre de "null," consécutifs trouvés !
Résumé depuis f.c.l.php :
======== Etienne SOBOLE a écrit :
>
> Ça donne :
>
> var expr = /(null,)+/
> var tRes = expr.exec(sDossier);
> while (tRes)
> {
> var sDossier = sDossier.replace(expr,
"@N" + (tRes[0].length / tRes[1].length) + "@");
> var tRes = expr.exec(sDossier);
> }
>
> et ca remplace une liste de null, par @Nx@
> où x est le nombre de "null," consécutifs trouvés !
Résumé depuis f.c.l.php :
======== Etienne SOBOLE a écrit :
>
> Ça donne :
>
> var expr = /(null,)+/
> var tRes = expr.exec(sDossier);
> while (tRes)
> {
> var sDossier = sDossier.replace(expr,
"@N" + (tRes[0].length / tRes[1].length) + "@");
> var tRes = expr.exec(sDossier);
> }
>
> et ca remplace une liste de null, par @Nx@
> où x est le nombre de "null," consécutifs trouvés !
Le 13/07/2008 17:49, SAM a écrit :
function dorepnull(sujet) {
sujet = sujet.replace(/(?<=[[,])(null,)*null[],]/,
function(match) {
return '#' + match.length/5 + match.substring(match.length-1);
});
return sujet;
}
alert(dorepnull($b));
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));
------------------------------------------------------------------------
Le 13/07/2008 17:49, SAM a écrit :
function dorepnull(sujet) {
sujet = sujet.replace(/(?<=[[,])(null,)*null[],]/,
function(match) {
return '#' + match.length/5 + match.substring(match.length-1);
});
return sujet;
}
alert(dorepnull($b));
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));
------------------------------------------------------------------------
Le 13/07/2008 17:49, SAM a écrit :
function dorepnull(sujet) {
sujet = sujet.replace(/(?<=[[,])(null,)*null[],]/,
function(match) {
return '#' + match.length/5 + match.substring(match.length-1);
});
return sujet;
}
alert(dorepnull($b));
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));
------------------------------------------------------------------------
Rhazut, je pensais pourtant que les assertions arrières faisaient partie
du tronc commun Perl/PCRE.
Si ça peut aider :
<http://developer.mozilla.org/fr/docs/R%C3%A9f%C3%A9rence_de_JavaScript_1.5_Core:Objets_globaux:RegExp>
(sic)
les assertions avant,
décrites aux lignes (?=), (?!) et (?:) dans ce tableau
(/sic)
Où il semblerait que le "positive lookbehind assertion"
(je regarde devant par l'arrière)
doive (peut-être ?) s'écrire :
(?:[[,]) ou : (?:[[,])
Autre problème, il ne comprend pas non plus [],] alors que [],] marche bien.
Ha!? mon interrogation à ce sujet n'était donc pas si futile.
------------------------------------------------------------------------
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);
});
}
------------------------------------------------------------------------
Rhazut, je pensais pourtant que les assertions arrières faisaient partie
du tronc commun Perl/PCRE.
Si ça peut aider :
<http://developer.mozilla.org/fr/docs/R%C3%A9f%C3%A9rence_de_JavaScript_1.5_Core:Objets_globaux:RegExp>
(sic)
les assertions avant,
décrites aux lignes (?=), (?!) et (?:) dans ce tableau
(/sic)
Où il semblerait que le "positive lookbehind assertion"
(je regarde devant par l'arrière)
doive (peut-être ?) s'écrire :
(?:[[,]) ou : (?:[[,])
Autre problème, il ne comprend pas non plus [],] alors que [],] marche bien.
Ha!? mon interrogation à ce sujet n'était donc pas si futile.
------------------------------------------------------------------------
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);
});
}
------------------------------------------------------------------------
Rhazut, je pensais pourtant que les assertions arrières faisaient partie
du tronc commun Perl/PCRE.
Si ça peut aider :
<http://developer.mozilla.org/fr/docs/R%C3%A9f%C3%A9rence_de_JavaScript_1.5_Core:Objets_globaux:RegExp>
(sic)
les assertions avant,
décrites aux lignes (?=), (?!) et (?:) dans ce tableau
(/sic)
Où il semblerait que le "positive lookbehind assertion"
(je regarde devant par l'arrière)
doive (peut-être ?) s'écrire :
(?:[[,]) ou : (?:[[,])
Autre problème, il ne comprend pas non plus [],] alors que [],] marche bien.
Ha!? mon interrogation à ce sujet n'était donc pas si futile.
------------------------------------------------------------------------
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);
});
}
------------------------------------------------------------------------
------------------------------------------------------------------------
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);
});
}
------------------------------------------------------------------------
Puisque les assertions en avant sont reconnues, on peut alors simplifier
------------------------------------------------------------------------
function dorepnull(sujet) {
return sujet.replace(/[[,](null,)*null(?=[],])/g,
function(match) {
return match.substring(0,1) + '#' + match.length/5;
});
}
------------------------------------------------------------------------
------------------------------------------------------------------------
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);
});
}
------------------------------------------------------------------------
Puisque les assertions en avant sont reconnues, on peut alors simplifier
------------------------------------------------------------------------
function dorepnull(sujet) {
return sujet.replace(/[[,](null,)*null(?=[],])/g,
function(match) {
return match.substring(0,1) + '#' + match.length/5;
});
}
------------------------------------------------------------------------
------------------------------------------------------------------------
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);
});
}
------------------------------------------------------------------------
Puisque les assertions en avant sont reconnues, on peut alors simplifier
------------------------------------------------------------------------
function dorepnull(sujet) {
return sujet.replace(/[[,](null,)*null(?=[],])/g,
function(match) {
return match.substring(0,1) + '#' + match.length/5;
});
}
------------------------------------------------------------------------
------------------------------------------------------------------------
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);
});
}
------------------------------------------------------------------------
Puisque les assertions en avant sont reconnues, on peut alors simplifier
------------------------------------------------------------------------
function dorepnull(sujet) {
return sujet.replace(/[[,](null,)*null(?=[],])/g,
function(match) {
return match.substring(0,1) + '#' + match.length/5;
});
}
------------------------------------------------------------------------
J'aime bien ta notion "simplifier" en allongeant la RegExp :-)
(bon ... encore kek z'années et je commencerai à peut-être y comprendre
kek chose en expression régulière)
------------------------------------------------------------------------
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);
});
}
------------------------------------------------------------------------
Puisque les assertions en avant sont reconnues, on peut alors simplifier
------------------------------------------------------------------------
function dorepnull(sujet) {
return sujet.replace(/[[,](null,)*null(?=[],])/g,
function(match) {
return match.substring(0,1) + '#' + match.length/5;
});
}
------------------------------------------------------------------------
J'aime bien ta notion "simplifier" en allongeant la RegExp :-)
(bon ... encore kek z'années et je commencerai à peut-être y comprendre
kek chose en expression régulière)
------------------------------------------------------------------------
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);
});
}
------------------------------------------------------------------------
Puisque les assertions en avant sont reconnues, on peut alors simplifier
------------------------------------------------------------------------
function dorepnull(sujet) {
return sujet.replace(/[[,](null,)*null(?=[],])/g,
function(match) {
return match.substring(0,1) + '#' + match.length/5;
});
}
------------------------------------------------------------------------
J'aime bien ta notion "simplifier" en allongeant la RegExp :-)
(bon ... encore kek z'années et je commencerai à peut-être y comprendre
kek chose en expression régulière)