Advertisement
dariys

Untitled

Jun 2nd, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function searchSubstr( fullText, searchText, allowOverlap ){
  2.   if(!searchText){return 0;}
  3.   var regex = new RegExp(searchText, 'igm'), count=0, substr;
  4.   while(substr=regex.exec(fullText)){
  5.      count++;
  6.     if(allowOverlap!==false){
  7.       regex.lastIndex -= Math.ceil(substr.length/2);
  8.     }
  9.   }
  10.   return count;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement