const fs = require('fs'); const file = 'src/lib/growth-pages.ts'; let content = fs.readFileSync(file, 'utf8'); // The file has two sections: allUseCases and useCasePageContent // They might both be duplicated. function removeSecond(text, regexStr) { const regex = new RegExp(regexStr, 'g'); let match; let count = 0; let indices = []; while ((match = regex.exec(text)) !== null) { indices.push(match.index); } if (indices.length > 1) { console.log("Found " + indices.length + " instances of " + regexStr + ", removing from second instance"); // We will remove from the second instance to the end of the object // This is tricky for nested objects. } }