title: Highlight multiple keywords for jQuery.autocomplete
body: <p>I'm using the jQuery <a href="http://docs.jquery.com/Plugins/Autocomplete" rel="noreferrer">Autocomplete plugin</a>, but I'm having some problems with the result highlighting. When a match is found, but the entered keyword contains spaces, there's no highlighting. Example:</p>
  
  <p>search = "foo", result = "foo bar", displayed = "<b>foo</b> bar"</p>
  
  <p>search = "foo ba", result = "foo bar", displayed = "foo bar"</p>
  
  <p>So, I'm trying to fix this using the <a href="http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions" rel="noreferrer">highlight option</a> of the autocomplete function where you can use a function to do some custom stuff with the results. Currently I have this:</p>
  
  <p><pre><code>$('.autocomplete').autocomplete('getmatch.php', {
      highlight: function(match, keywords) {
          keywords = keywords.split(' ').join('|');
          return match.replace(/(get|keywords|here)/gi,'&lt;b&gt;$1&lt;/b&gt;');
      }
  });</pre></code></p>
  
  <p>The replace function replaces all the matched words in the string with a bold version, that works. However, I don't know how to get the keywords into that function. I though I'd split them, and then join them with a '|', so "foo bar" ends up like "foo|bar". But something like this doesn't seem to work:</p>
  
  <p><code><pre>return match.replace(/(keywords)/gi,'&lt;b&gt;$1&lt;/b&gt;'); // seen as text, I think</pre></code></p>
  
  <p><code><pre>return match.replace('/'+(keywords)+'/gi','&lt;b&gt;$1&lt;/b&gt;'); // nothing either</pre></code></p>
  
  <p>Any ideas?</p>