JavaScript Program to Check Whether Given String contains a Word or not Using Regular Expression

Write a JavaScript program to check whether given string contains a word or not using regular expression.



Source Code
<html>
<head>
    <title>Regular expression to find given word</title>
    <script>
        function check()
        {
            var txt=document.getElementById('txt').value
            var re = /\bJavaScript\b/
            var res=re.test(txt)
            if(res)
                alert('Word found')
            else
                alert('Word not found')			
        }
    </script>
</head>
<body>
Enter text <input type="text" id="txt"/>
<input type="button" value="Submit" onclick="check()"/>
</body>
</html>
Output





"Coding Hub - Learn to code" app now available on Google Play Store