Tuesday, November 6, 2012
Thursday, January 26, 2012
Regex using groups in javascript
Convert the xml to uppercase except text or textContent and attribute values.
var XML_String="<start_tag><data>some data</data><data id=\"xyz\" id2=\"yyy\">some data2</data></start_tag>"
XML_String=XML_String.replace(/(<|<\/)([\"_a-zA-Z0-9\s=]*)(>)/gi, function(s, group1, group2,group3) {
if(group2.indexOf("\"")>-1){
var substr=group2;
substr=substr.replace(/([a-zA-Z0-9=_\s]*)(\")([_a-zA-Z0-9]*)(\")/gi,function(sb,group1,group2,group3,group4){
return group1.toUpperCase()+group2+group3+group4;
});
group2=substr;
}else{
group2=group2.toUpperCase()
}
return group1+group2+group3;});
Subscribe to:
Posts (Atom)