I made a short javascript function to replace accented letter with regular ones, and change all special characters to an underscore, but that did not worked correctly.
function removeAccents(mytext)
{
mytext=mytext.replace(new RegExp(/[őóö]/ig) ,’o');
mytext=mytext.replace(new RegExp(/[úűü]/ig) ,’u');
mytext=mytext.replace(new RegExp(/[á]/ig) ,’a');
mytext=mytext.replace(new RegExp(/[í]/ig) ,’i');
mytext=mytext.replace(new RegExp(/[é]/ig),’e');
mytext=mytext.replace(new RegExp(/[^a-zA-Z 0-9 ]+/g),” “).replace(new RegExp(/\s+/g),”_”);
return mytext;
}
The script has very strange behavior. When I tried to use on a string what contained accented letters, the script did not changed them to regular ones, but handle them as special characters.
When I tried to debug the script, I saw, the mytext variable never got the new value after the replaces, only after the last one. When I used the function in the Watch Expression tab, that give back the appropriate value, but didn’t when I run the script on normal way. I tried the script in more browsers, and all test had same result.
After some rest, I tried to find the problem again, and finally found the solution.
I stored the javascript code in a separate file, what was not UTF8 encoded, while the main html page, where I used the script was that.
On the firebug, everything seemed fine, but the encoding difference was enough to cause this hard-to-find reson.




















