pixxxel schubser wrote:
But you should not work with long long strings.
Better use ranges of unicode like this
… contents.replace(/[A-Z]/g, replaceWithWhatever); // is the same as
… contents.replace(/[\u0041-\u005A]/g, replaceWithWhatever);
… contents.replace(/[A-ZÀ-Ö]/g, replaceWithWhatever); new range added - is the same as
… contents.replace(/[\u0041-\u005A\u00C0-\u00D6]/g, replaceWithWhatever);
and so on
Good point. So, here's a function that will convert any string to its shortened form for GREP:
function shortenString(s){
var r1, r2, a, i;
r1 = r2 = s[0];
a = [];
for (i = 1; i < s.length; i++){
if (s.charCodeAt() == r2.charCodeAt() + 1){
r2 = s;
if (i != s.length - 1) continue;
}
if (r1 != r2){
a.push(r1 + "-" + r2);
}
else {
a.push(r1);
}
r1 = r2 = s;
}
return a.join("");
}
Ariel
I've updated the link to include the shortened version as well using the above function:
http://www.id-extras.com/uploads/AllUnicodeCapitals.html
Ariel