Strings and regular expressions

Template literals, string methods and regular expressions — the same as JavaScript, with types.

Runs in Zerethon IDE · TypeScript 7 Official TypeScript documentation ↗
main.ts
const fullName = 'Ada Lovelace';
console.log(`${fullName.toUpperCase()} (${fullName.length})`);
console.log('a,b,c'.split(','), ['x', 'y'].join('-'), '7'.padStart(3, '0'));

const text = 'Order 12 shipped, order 7 pending';
const numbers: string[] = text.match(/\d+/g) ?? [];
console.log(numbers.map(Number));

const m: RegExpMatchArray | null = text.match(/order (\d+) pending/);
console.log(m ? m[1] : 'no match');

Output

ADA LOVELACE (12)
[ 'a', 'b', 'c' ] x-y 007
[ 12, 7 ]
7

match() returns RegExpMatchArray | null, so strict mode makes you handle “no match” — ?? [] or a check.