/ Published in: JavaScript
Released into the public domain. needle must be a regex; to pass a string, escape it and pass as new RegExp(escaped_string, 'g'). Case sensitive.
Expand |
Embed | Plain Text
function global_search(needle, haystack) { if(typeof needle=='function') { haystack_remaining = haystack; match = ''; matches = []; results = []; result = 0; offset = 0; var i = 0; while(haystack_remaining && (result = haystack_remaining.search(needle)) != -1) { match = haystack_remaining.match(needle); match = match[0]; matches[matches.length] = match; results[results.length] = result + offset; haystack_remaining = haystack_remaining.substring(result + match.length); offset += result + match.length; i++; } return [results, matches]; } else return false; }
You need to login to post a comment.
