In the following code, I have used RegExp to check E with Case Sensitive Modifier i in the string The best things in life are free. But it is returning true even if there is no uppercase E in the string.
<html>
<body>
<script type="text/javascript">
var patt1=new RegExp("E","i");
document.write(patt1.test("The best things in life are free"));
</script>
</body>
</html>
Regular expressions are case sensitive by default just get rid of the
iflag. Theiflag stands for ignore case.note it’s typically easier to write regular expressions as:
but if you’re just testing for the presence of a fixed string it’s better to not use a regex at all
You can find out more about regular expressions and indexOf on mozilla’s javascript reference site