|
Wednesday Oct 11, 2006 The function replace can be used to replace a string with another string. A regular expression can be used to find the string.
<html>
<head>
<script type="text/javascript">
var str = new String("Hello World")
document.write(str+"<br/>")
var regEx = new RegExp ('World', 'gi') ;
str = str.replace(regEx, 'User')
document.write(str)
</script>
</head>
<body></body>
</html>
Output
Hello World
Hello User
|