
September 20th, 2012, 11:45 AM
|
|
|
|
jQuery - Script - partial match
Hi,
currently i have an array in jquery (static one, which doesnt change) like [ item1, item2....]/
i have a text area where user can put something like:
item111,
item222,
...
then i split textarea into an array, loop through this array, and for each item, i loop through the static array and find teh closest match. if it is closest match then i display: item111, <drop down of my static array with closes match selected>
this is how i do a closest match:
Code:
$.each(default_industries, function(){
match_regex = new RegExp('['+user_text+']{1,}');
//match_regex = new RegExp('['+this+']{1,}');
var this_count = this.match(match_regex);
if (this_count){
if ( this_count[0].length > last_count ) {
default_index = i;
last_count = this_count[0].length;
}
}
i++;
});
default_index is used to then get the array item of static array that "matched" closely.
Anyway the question: is there a more efficient way of matching two strings?
|