INNER CODE UNIT · TypeScript
jsonMatch
austin-starks/Promptimizer · src/utils/index.ts:39
const jsonMatch = text.match(/{[\s\S]*}/);
if (!jsonMatch) {
return undefined;
}
// Extract the JSON string from the matched content
let jsonString = jsonMatch[0];
// Remove known non-JSON markers and sanitize the string
jsonString = jsonString
.replace(/```SQL/g, "")
.replace(/```sql/g, "")
.replace(/```JSON/g, "")
.replace(/```json/g, "")
.replace(/```/g, "")
.replace("\n", " ")
.replace(/[\u0000-\u001F\u007F-\u009F]/g, " "); // Remove non-printable characters