Comment

Remo

Hi can anyone please get me the solution with coding example for the below problem.

For example, you might want to allow multiple words to match so as ter ma should match Teresa Mayers, John Mayor and Maria Connor.
a solution is given above like make a regular expression with something like \b(ter|ma). but can you give an example with complete code

Replies

Emil Georgiev

To construct "\b(ter|ma)" from search string "ter ma" do the following:

  var search = 'ter ma';
  '\\b(' + search.trim().split(/\s+/).join('|') + ')'

Working example is here: https://jsfiddle.net/emilonlinester/f6rs7nx4/