const name = 'Alice'; const age = 25; const message = formatString( 'My name is {0} and I am {1} years old.', name, age );
console.log(message); // My name is Alice and I am 25 years old.
The regular expression captures the numeric index inside each placeholder. The callback uses that index to retrieve the corresponding argument. If the argument is missing, the original placeholder remains unchanged.