Strings and regular expressions
Template literals, common string methods, splitting and joining, and regular expressions.
Runs in Zerethon IDE · Node.js 22
Official JavaScript documentation ↗
main.js
const name = 'Ada Lovelace';
console.log(`${name} has ${name.length} characters`);
console.log(name.toUpperCase(), name.slice(0, 3), name.indexOf('Love'));
console.log(' padded '.trim() + '|', '7'.padStart(3, '0'));
console.log('a,b,c'.split(','), ['x', 'y'].join('-'));
console.log('a-b-c'.replaceAll('-', '+'), name.startsWith('Ada'), name.includes('love'));
const text = 'Order 12 shipped, order 7 pending';
console.log(text.match(/\d+/g));
const m = text.match(/order (\d+) pending/);
console.log(m ? m[1] : 'no match');
console.log(/^[\w.]+@\w+\.\w+$/.test('ada@example.com'));
Output
Ada Lovelace has 12 characters ADA LOVELACE Ada 4 padded| 007 [ 'a', 'b', 'c' ] x-y a+b+c true false [ '12', '7' ] 7 true
- Strings cannot be changed in place; methods return new strings.
replace()with a string changes only the first match — usereplaceAll()or a regex with thegflag.match()returnsnullwhen nothing matches; check before indexing.