I'm parsing an XML document with JS, changing to lower case every first letter of the tags names. I.E. <MyTagName></MyTagName>
will become <myTagName></myTagName>
, very simple and everything works fine. I'm using a regex to find all the tags and replacing the name with the camel version, like this:
regex = /(<)(\/){0,1}([A-Z]*)(\/){0,1}(>)/ig;
result = result.replace(regex, function(s, m0, m1, m2, m3, m4){
return m0 + (m1 ? m1 : "") + camelNotation(m2) + (m3 ? m3 : "") + m4;
});
My question is: is there a way to get some of the parameters in the anonymous function which is the second argument of my replace
function in a more dynamic way, like an array? Something like
result = result.replace(regex, function(s, param[]){
return param[0] + (param[1]? param[1] : "") + camelNotation(param[2]) + (param[3] ? param[3] : "") + param[4];
});
I may use arguments[i]
, but I would like to know if I can customize my parameters in the function signature.
Thank you
I often use the following simple higher-order function:
e.g.