function cleanString(text: string): string {
// Step 1: Remove parentheses and their content (non-greedy)
let cleaned: string = text.replace(/\([^)]*\)/g, "");
// Step 2: Collapse multiple spaces into one
cleaned = cleaned.replace(/\s+/g, " ").trim();
return cleaned;
}
const original = "Hello (remove this) from the future (and this too)";
const result: string = cleanString(original);
console.log("Original:", original);
console.log("Cleaned :", result);
/*
run:
"Original:", "Hello (remove this) from the future (and this too)"
"Cleaned :", "Hello from the future"
*/