javascript – How can I compare words using regular expression but ignore certain ones? – Education Career Blog

I have made a search engine and I am comparing a search string against a list of words. However I want to omit words like "How,do,i". So if the user search for "How do I find my IP?". If I have 3 other items beginning with How do I it wouldn’t really be able to return a good relevancy.

right now its setup (a-z0-9)+userinput+(a-z0-9) Wanted to have a list of words to be omitted so they would not be matched. I am using javascript only please assist.


Another updated example, now using \b

    <script type="text/javascript">
        var unwanted = new RegExp(
                "(how|where|what) do (I|you)",
                "or phrases",
          .join("|")+ ")(?=\\b)",
        "ig" // Ignore case, global

        function dosearch(e){
            var search =;
            search = search.replace(unwanted,"");

            return false;
    <form method="post" action="" onsubmit="return dosearch(this)">
        search: <input type="text" name="search">

Leave a Comment