1

I have been struggling with this issue for quite some time, the code works fine with latin chars, as for cyrillic, jquery don't recognize it at all.

$('p').each(function() {   var $this = $(this);
    $this.html($this.text().replace(/\b(\w+)\b/g, "<span>$1</span>"));  
});

I have also tried the following code, but for some reason, jQuery skips every second word and doesn't wrap it :(

$(this).html($(this).text().replace(/\s([a-zA-Zа-яА-ЯёЁ]+)\s/g, " <span> $1 </span> "));

Any hint?

scumah
  • 6,273
  • 2
  • 29
  • 44
mbassioni
  • 11
  • 1
  • 1
    Check this: http://stackoverflow.com/questions/14659594/how-to-make-regular-expression-match-only-cyrillic-bulgarian-letters – Rolice Feb 20 '14 at 15:03

1 Answers1

0

It appears JS isn't so good at this (as noted here by @Rolice in the comments above). In most languages, you merely need to change the locale.

You may have to do something like this:

replace(/(^|[^\w\u0400-\u04FF])(\w+)([^\w\u0400-\u04FF]|$)/,
  "$1<span>$2</span>$3");
Community
  • 1
  • 1
Adam Katz
  • 14,455
  • 5
  • 68
  • 83