I am using openai to get subject lines, choices returning string not array/object, i need to split string by numbers.
var choices = "1. "Don't Miss Out: Exclusive Deals Inside!" 2. "Hurry! Limited Time Offer Inside" 3. "Unlock Savings: Open This Email Now" 4. "Last Chance to Save Big"";
choices = choices.split('/[0-9]+./');
console.log(choices)
this is not working for me. its showing all string into single array index.
i needed output as
["Don't Miss Out: Exclusive Deals Inside!","Hurry! Limited Time Offer Inside","Unlock Savings: Open This Email Now","Last Chance to Save Big"]
3
Answers
Define the RegExp without quotes:
Open AI is perfectly capable of returning the output in the format you want. Instead of parsing the returned output instruct the AI to return the output to you in as a JSON array of strings.
While there is the option of
choices.split(/[0-9]+./)
you could always do:Also, note your string is invalid. You would have better luck using template literals.