JavaScript string methods and regular expressions
Strings are immutable sequences of characters, and their methods return new strings. split turns a string into an array, join does the reverse, trim removes surrounding white space, and padStart fills to a given width. The replace method with a string replaces only the first match, while a regular expression with the g flag replaces every match.
JavaScript
console.log("a-b-c".split("-").reverse().join("+"));
console.log(" padded ".trim().padStart(8, "*"));
const text = "The year 2024 and 1999 were notable";
console.log(text.match(/\d{4}/g).join(" "));
const m = "2024-03-15".match(/^(\d{4})-(\d{2})-(\d{2})$/);
console.log(m[1], m[2], m[3]);
console.log("hello world".replace(/o/g, "0"));
console.log("camelCaseString".replace(/([A-Z])/g, "_$1").toLowerCase());
console.log(/^[\w.]+@[\w.]+\.\w+$/.test("ada@example.com"), /^[\w.]+@[\w.]+\.\w+$/.test("not an email"));