How to add span tags to each Chinese and English words in a string?
I'm trying to add span tags to each word of user's input for further manipulation. My attempt so far can only find english words and attach tags? how do I attach span tags to both to english words and Chinese Characters t if user's input has Chinese charecters within.
userInput="hello world ????"
var regex = /(<.+?<\/.+?>|\S+)/g;
var result = userInput.replace(regex, function(a) {
return "<span id=" + (++id) + ">" + a + "</span>";
});
Answers 1
Use this regex instead
It is going to consider anything equal or greater than
\u00ff
a word.