Skip to content

Instantly share code, notes, and snippets.

@pete-otaqui
Created July 13, 2010 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pete-otaqui/473455 to your computer and use it in GitHub Desktop.
Save pete-otaqui/473455 to your computer and use it in GitHub Desktop.
// strip all slashes (ignored by search anyway)
var reVal = this.val().replace(/[\\\/]/,'');
// strip all non alpha-numeric (or space) chars too
reVal = reVal.replace(/[^a-zA-Z0-9 ]/,'');
// make a regexp to match before, 'val()' and after
var regex = new RegExp('(.*?)('+reVal+')(.*?)', 'i');
// inject styling
name = name.replace(regex, '$1<span class="blq-search-underline">$2</span>$3');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment