Find and Replace

<script type="text/javascript">

var testString = 'This is the subject of my experiment';

//A simple find and replace statement
var simpleFind = 'experiment';
var simpleReplacement = 'simple find and replace';

//Using a regular expression for more advanced find and replace
var regexFind = /experiment/;
var regexReplacement = 'Regex';

document.write('Original: ' + testString + '<br>');
document.write('String replace: ' + testString.replace(simpleFind,simpleReplacement) + '<br>');
document.write('Regex replace: ' + testString.replace(regexFind,regexReplacement));

</script>

0 Comments

You must be logged in to post a comment.