Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Capitalize first letter of each word const title = "hello world from js"; const result = title.replace(/\b\w/g, (char) => char.toUpperCase()); // "Hello World From Js" // Replace numbers with their squares "1 + 2 = 3".replace(/\d+/g, (n) => n ** 2); // "1 + 4 = 9" // Use capture groups in replacement function "2024-06-15".replace( /(\d{4})-(\d{2})-(\d{2})/, (_, y, m, d) => `${d}/${m}/${y}` ); // "15/06/2024"
Result
Open