The equality of LIKE '%$word%' in JavaScript RegExp AKA How to make a JavaScript search engine

I have a localStorage object that contains JSON data that yes, I have already parsed.

Within that data, I wish to search an array for something, such as "ANYTHING HERE "+keyword+"ANYTHING HERE"; Like an SQL "LIKE ''" query.

Ahh yes, indexOf seems to work fine for it. All I have to do now is just make a simple RegExp to validate the search input (only for length and characters--nothing fancy.)

You see, I am working on a local application that Google Chrome users will be able to set as their homepage, and hopefully, I can come up with some cool never-before-seen features.



If you want to know if one string appears within another you might want to use the indexOf method.

if(jsonstring.indexOf(keyword) != -1){
    console.log("keyword appears in jsonstring");

May be this if you are using javascript

pattern = /keyword/g
        // it matches the element that has the text 'keyword' in it

Try this regex pattern /\w*X\w*/gi

Example: Find any like OR, AND to replace uppercase.

g: Global i: insensitive m: multi-line

let _like = "examPle OrTeeeeest tOst iAnDi liKe oRNot MK7".replace(/\w*AND\w*|\w*OR\w*/gi, 
  function (x) {
    return x.toUpperCase();


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.