title: javascript jquery regexp replace
body: <p>I'm trying to create a dynamic searchbar and i need help.</p>
  
  <p>Right now im trying to replace a string with another string but i cant seem to succeed.</p>
  
  <p>Im getting input from the user:</p>
  
  <pre><code>var location_keyword = $("#si_user_location").val();
  </code></pre>
  
  <p>Now i would like to replace a whitespace " " with a "|" to use this in my regexp as OR.</p>
  
  <p>For example if the user wrote "Turkey Alanya", i want it to be "Turkey|Alanya" so that the search hits for both Turkey OR Alanya.</p>
  
  <p>i tried something like this but it didnt work</p>
  
  <pre><code>var location_keyword = $("#si_user_location").val();
  location_keyword.replace(" ","|");
  var regexp_loc = new RegExp(location_keyword, "i");
  </code></pre>
  
  <p>i used to do this in PHP before with expressions such as:</p>
  
  <pre><code>preg_replace('/'.preg_quote($keyword).'/i', "&lt;span&gt;$0&lt;/span&gt;", $string)
  </code></pre>
  
  <p>and i could replace strings caseinsensetive like this, how can i do this in js?</p>
  
  <p>I used the last expression in PHP to highlight the keyword in the results, which i would like to do aswell in js.</p>
  
  <p>hope i can get some help, thanks in advance! :)</p>
  
  <p>best of regards,
  alexander</p>