Skip to content Skip to sidebar Skip to footer

Regex - Match Multiple Unordered Words In A String

I have a list of names and I am looking to filter the list to only return names that contains both the last and first names. Let's say I am looking for 'Joe Doe' I have the current

Solution 1:

This lookahead based regex should work:

/(?=.*?\bJoe\b)(?=.*?\bDoe\b).*/i

Testing:

/(?=.*?\bJoe\b)(?=.*?\bDoe\b).*/.test('Joe Doe'); // true
/(?=.*?\bJoe\b)(?=.*?\bDoe\b).*/.test('Doe Joe'); // true

Post a Comment for "Regex - Match Multiple Unordered Words In A String"