How to replace multiple consecutive question marks (?) with a single question mark in TypeScript

1 Answer

0 votes
const str = "What??? Why?? How?????";

// Use regular expression to match one or more '?'
const result: string = str.replace(/\?+/g, "?");

console.log(result);



/*
run:

"What? Why? How?" 

*/

 



answered Jul 24, 2025 by avibootz
...