I'm trying to match a name obtained from server against input provided by a user, the complete name may or may not be known entirely by the user, for example I should be able to match the following:
Name Obtained: Manuel Barrios Pineda
Input given: Manuel P
Right until now I've tried with this code:
var name_obtained = 'Manuel Barrios Pineda';
var re = new RegExp('\b[' + name_obtained + ']+\b');
var input_string = 'Manuel';
if (input_string.match(re)) {
alert('Match');
} else {
alert('No Match');
}
Here's an example: jsfiddle example
EDIT 1: It's required to match input like 'Manuel B', 'Manuel P'
b.new RegExp('\\b[' + name_obtained + ']+\\b');String literal syntax has escape sequences as well, so to use a\bin the regex, you need to provide a literal\character, which is done with\\."Manuel Pinzon", too.