Regex that detects if the key has a missing character
const placeholders = { "Luke": "{{candidate_first_name}}", "xxx@gmail.com": "{{candidate_email}}", } const text = <div>Hi Luke ,</div><div><strong>Email: </strong>xxx@gmail.com</div> export default function removeTextPlaceholders( text: string, placeholders: any ) { try { for (const [key, value] of Object.entries(placeholders)) { if (value) { const regex = new RegExp(`^${key}(?:\\s*|.{0,1})$`, 'g'); // Check if the key is a complete match before replacing