I want regExp to test for two ‘Hello’-s and return true but it only returns false even though I cannot find anything wrong with my code. How do I fix this? Please also suggest what is wrong with the code.
<html>
<body>
<script type="text/javascript">
var str ="Hello Hello";
var patt = /(hello){2}/gi;
var result =patt.test(str);
document.write("Returned value: " + result);
</script>
</body>
</html>
You forgot the space:
Your original RE matches “HelloHello”, but not two occurences of “Hello”.