Search Full Text @ Javascript | PHP + MONGODB by REGEX ( String contains all search keyword | AND not OR)

JAVASCRIPT function fullTextCompare(myWords, toMatch){ //Replace regex reserved characters myWords=myWords.replace(/[-\/\\^$*+?.()|[\]{}]/g, ‘\\$&’); //Split your string at spaces arrWords = myWords.split(” “); //Encapsulate your words inside regex groups arrWords = $.map( arrWords, function( n ) { return [“(?=.*”+n+”)”]; }); //Create a regex pattern sRegex = new RegExp(“^”+arrWords.join(“”)+”.*$”,”im”); //Execute the regex match return(toMatch.match(sRegex)===null?false:true); } //Using it: console.log( fullTextCompare(“my word”,”I’m …

19+ JavaScript Shorthand Coding Techniques – Công thức rút gọn

This really is a must read for any JavaScript based developer. I have made this post as a vital source of reference for learning shorthand JavaScript coding techniques that I have picked up over the years. To help you understand what it going on I have included the longhand versions to give some coding perspective …