Reputation: 3525
Does anyone know a way in Javascript to efficiently check if a string contains all the characters of a substring in order, even if they are not sequential (i.e. possibly separated by other content)?
Example:
hasChars("turtle", "I like tu uurtle"); // true
hasChars("turtle", "t,u,r,t,l,e,"); // true
hasChars("turtle", "turtel"); // false
Upvotes: 0
Views: 58
Reputation: 67968
var patt = new RegExp(".*?t.*?u.*?r.*?t.*?l.*?e.*");
console.log(patt.test('I like tuuu ur,t,l,e,')); // true
Upvotes: 1