gruss Joachim,
Lässt sich sowas einfacher umgehen, als gleich
mit einer callback-funktion zu arbeiten?
noe, du kommst um einen »callback« nicht herum ...
... Dein beispiel aufgreifend:
Array.make=(function(list){var arr;if(list&&(typeof list.length=="number")){arr=Array.prototype.slice.call(list)}return arr});
var regex = /^([a-z]+)([0-9]+)([a-z]+)([0-9]+)([a-z]+)([0-9]+)([a-z]+)([0-9]+)([a-z]+)([0-9]+)([a-z]+)([0-9]+)$/i;
var str = "a1b2d3e4f5g6";
function sx_replacer (str, repl, regex) {
return str.replace(regex, (function () {
alert((({}).toSource && Array.make(arguments).toSource()) || Array.make(arguments).toString());
return (arguments[1] + repl);
}));
//return ("\"" + str.replace(regex, "$155") + "\" bzw. \"" + str.replace(regex, "$11") + "\"");
}
alert(sx_replacer(str, "55", regex)); // ergibt wie gewünscht a55
alert(sx_replacer(str, "1", regex)); // ergibt jetzt wie gewünscht a1
so long - peterS. - pseliger@gmx.net
--
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]