Hi Aarti,
there are actually two issues with your example.
- There is no need for quotes around your pattern literal. Regular Expressions are first class citizens in JavaScript. Look here Regular Expression Cheat Sheet[^] or here W3 Schools RegExp Object[^]
- Certain characters in Regular Expressions have a special meaning so they'll have to be escaped if you want the character interpreted literally.
Here a fully working example I cooked up for you:
<html>
<body>
<h1>Test</h1>
</body>
<script type="text/javascript">
var patt1=/\:\)/g; //Notice how there are no quotes and the : and ) are escaped by a \
alert(":):):)".replace(patt1,"*"));
</script>
</html>
The alert message shows three asterisks!
Regards,
— Manfred