I want to replace individual words in an input, and these words include international (Turkish) characters. I am trying to do this as such:
replace(/\s([\u0000-\u007F\u00c7-\u015f]+)\s/g, "<span>$1</span>");
I have changed this around various ways in order to exclude spaces, this is just the most recent failed attempt. What's happening now is, a paragraph is matched instead of the individual words. In other tests, with slightly different incarnations of the above regex, half the word will be matched, with the boundary being at a special character (that is appropriately rendered elsewhere, strangely enough.)
Note that replacing \s above with \b doesn't help things.
What is a better way to accomplish what I'm trying to, in the above code?
You can use the following approaches:
\u0020 and you can remove it from the code ranges (see demo):[\u0000-\u001F\u0021-\u007F\u00c7-\u015f]+
(?:(?!\s)[\u0000-\u007F\u00c7-\u015f])+
Note that the first option is much quicker and should be used, the second is just to show what regex can do in JS :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With