0

I'm looking for some plugin/script that search some string and bold matching part (fuzzy search)

Below parent > key > result example.

"Hello world" => "hel" => Hello world

"Hello world" => "hewd" => Hello world

I've found this - it has fuzzy option but its not able to bold matching part or parts of string.

Do you know any plugin like this.

Adam Pietrasiak
  • 12,773
  • 9
  • 78
  • 91
  • This should help you out http://stackoverflow.com/questions/9794851/find-text-string-in-jquery-and-make-it-bold/9795091#9795091 – elclanrs Sep 02 '13 at 19:22

1 Answers1

0

A simple example:

$('element').html(function() {
  return $(this).text().replace(/[hewd]/gi, '<strong>$&</strong>');
});

Then you can abstract it by building a dynamic regex. The above will match any h,e,w,d letter, if you want to match a whole word, you can use word boundaries \b:

/\bhello\b|[ewd]/ //=> Will match "hello" and all "e,w,d" letters

Demo: http://jsbin.com/OKUjAtO/3/edit

elclanrs
  • 92,861
  • 21
  • 134
  • 171