JSFiddle - React, Tailwind, and code Playground

by kougiland

HTML

<form role="form">
    <input type="text" id="search" placeholder="Search...."/>
</form>

JavaScript

// RegExp constructor flags: new RegExp('elements','flags')
// i  Ignore case (both lowercase and uppercase letters will match)
// g  Global (allow multiple matches)
// m  Multiline (^ and $ will match the beginning/end of lines)

$('#search').keyup(function(){
    var searchFieldValue = $('#search').val(),
        re = new RegExp(searchFieldValue, "img"),
        str = "The sky is awake so I am awake so we have to play";
     if ( str.search(re) == -1 ){
          console.log("Does not contain " + searchFieldValue );
     }else{
          console.log("Contains " + searchFieldValue);
     }
});