Toggle navigation
Genres
Frontend (2)
JavaScript (6)
Database (2)
Linux Server (3)
Web Apps (4)
Misc (4)
Search
List
New Tutorials
Last Modified Tutorials
</>
Code examples
code
smiko
javascript
basic
035stringmethods_replace.js
035stringmethods_replace.js
/** * String methods: replace * The replace() method returns a new string with some or all matches of a * pattern replaced by a replacement. */ var str, x, xg, xi; str = "simple example of simple string BIG big"; x = str.replace('simple', 'not simple'); //replace first match xg = str.replace(/s\w+e/g, 'not simple'); //replace all matches xi = str.replace(/BiG/i, 'SmaLL'); //case insensitive replacement console.log(x); // not simple example of simple string BIG big console.log(xg); // not simple example of not simple string BIG big console.log(xi); // simple example of simple string SmaLL big
Reload page
Preview
W3C validation
Edit Code
JS Console