Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1060

Regex wordwrap with UTF8 characters in JS

$
0
0

I've already read all the articles in here which touch a similar problem but still don't get any solution working. In my case I want to wrap each word of a string with a span. The words contain special characters like 'äüö...'

What I am doing at the moment is:

var textWrap = text.replace(/\b([a-zA-Z0-9ßÄÖÜäöüÑñÉéÈèÁáÀàÂâŶĈĉĜĝŷÊêÔôÛûŴŵ-]+)\b/g, "<span>$1</span>");

But what happens is that if the äüñ or whatever NON-Ascii character is at the end or at the beginning it also acts like a boundary. Being within a word these characters don't act as a boundary.

'Ärmelkanal' becomes Ä<span>rmelkanal</span> but should be <span>Ärmelkanal</span>'Käse'works fine... becomes <span>Käse</span>'diré' becomes <span>dir</span>é but should be <span>diré</span>

Any advice would be very appreciated. I need to do that on clientside. By the way, did I mention that I hate regular expressions?

Thank You very much!


Viewing all articles
Browse latest Browse all 1060

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>