1

I have a list that might look like this:

<ul>
 <li>Table</li>  <!-- English -->
 <li>मेज</li>    <!-- Hindi -->
 <li>میز</li>   <!-- Urdu -->
</ul>

I want to use jQuery to read the characters in the list-item and if it finds any characters in the Arabic unicode range (0x0600 - 0x06FF), underline it.

Here is what I have:

$("li:contains(/[\u0600-\u06FF]/)").css( "text-decoration", "underline" );

It should match the third item but I'm obviously doing something wrong. Perhaps regular expressions are not allowed by :contains in jQuery selectors...

Pushker Yadav
  • 866
  • 1
  • 8
  • 15
theglossy1
  • 543
  • 3
  • 13
  • I see that people have already been thinking about this. This may be what I want to do: http://stackoverflow.com/questions/190253/jquery-selector-regular-expressions – theglossy1 Mar 17 '15 at 09:09

1 Answers1

3

You can use filter() with a RegExp.
Try the following:

var regex = new RegExp(/[\u0600-\u06FF]/);

$("li").filter(function() {
    return regex.test($(this).text());
}).css("text-decoration", "underline");
Para
  • 3,681
  • 4
  • 23
  • 34