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 () {
$(function () {
$(".replaceText").html(function (i, text) {
if ($('.replaceText > span.dbOrange').length) {
return;
}
else {
return text.replace(/\w+\s\w+/, function (match) {
return '<span class="dbOrange">' + match + '</span>';
});
}
});
});
});
This works fine in 9 out of 10 cases. The first two words are styled with orange color and bold. However, if a the the second word contains an Umlaut like ä ö ü the Regex breaks at this character and it looks like the word would end there.
Can you help me with a more failsafe solution?
Kind regards