var s = "aaa bbb ccc ddd eee"; alert( (s.match(/aaa|bbb|ccc/ig) || []).length === 3 ) var s = "aaa bbb ccc ddd bbb eee bbb"; alert( (s.match(/aaa|bbb|ccc/ig) || []).length === 3 )