How to replace multiple consecutive question marks (?) with a single question mark in Node.js

1 Answer

0 votes
const str = "Hello??? How are you?? What is your Wi-Fi password????";

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

console.log(result);



/*
run:

Hello? How are you? What is your Wi-Fi password?

*/

 



answered Jul 24, 2025 by avibootz
...