Skip to content Skip to sidebar Skip to footer

Javascript String.replace Fails At German Umlaute

I am using a small Javascript/Jquery function to inject a element into some text, if there is not already such an element. The code looks like this: $(document).ready(function ()

Solution 1:

Try this:

/\S+\s\S+/

\S matches non-whitespace characters.

Solution 2:

\w is a shorthand for [A-Za-z0-9_], which does not contain the umlaut character. If you want other ranges included, you'll need to create an explicit set of acceptable characters.

Solution 3:

Yes this is a common issue for non english characters in Javascript regular expressions. They will not be recognized by \w. You will have to specify the unicode representation \uXXXXX for each of the special characters separately

Post a Comment for "Javascript String.replace Fails At German Umlaute"