I have an string with HTML format, and I need to replace ALL the math exponents in HTML format <sup></sup>, to math exponents without HTML format.
I'm using the replace() method, but I need find and replace 100 exponents, from <sup>1</sup> to <sup>100</sup>, and I should write all the numbers (from 1 to 100).
var copiar = texto.
replace(/<br>/g, "\n").
replace(/<sup><\/sup>/g, "").
replace(/<sup>2<\/sup>/g, "²").
replace(/<sup>3<\/sup>/g, "³").
replace(/<sup>4<\/sup>/g, "⁴").
replace(/<sup>5<\/sup>/g, "⁵").
replace(/<sup>6<\/sup>/g, "⁶").
replace(/<sup>7<\/sup>/g, "⁷").
replace(/<sup>8<\/sup>/g, "⁸").
replace(/<sup>9<\/sup>/g, "⁹").
replace(/<sup>10<\/sup>/g, "¹⁰");
...
replace(/<sup>100<\/sup>/g, "¹⁰⁰");
My question is: There is a way to automate this task? Thanks!
UPDATE: I'm doing this replacements because I'm developing an App for iOS, capable to print (in HTML format) and copy to clipboard (plane text). That's the reason because I'm replacement the <sup> numbers.
UPDATE 14/Oct/2014: I was needing to replace negative exponents too. Using the @minitech answer and modifying a little, I could be able to replace ALL the exponents (positive and negative). Maybe can be useful for someone, here the code:
var map = '⁰¹²³⁴⁵⁶⁷⁸⁹';
var copiar = texto.replace(/<sup>(\-*(\d*))<\/sup>/g, function (str, digits){
return Array.prototype.map.call(digits, function (digit) {
var exp = "";
if (digit != '-') {
exp += map.charAt(digit);
} else {
exp += "¯";
}
return exp;
}).join('');
});
x^100instead ofx¹⁰⁰, though. I don’t know about your typefaces, but it looks bad in mine…x¹⁰⁰.