Get values inside quotes in javascript, like in discord dyno bot uses ?poll "<title>" "<choice>" "<choice>"
, How do split the array so that I get the values of the title and choices in javascript
CodePudding user response:
1) You can easily achieve the result using regex
/(?<=")[^"] /
const str = `?poll "<title>" "<choice>" "<choice>"`;
const result = str.match(/(?<=")[^"] /g).filter((s) => s.trim());
console.log(result);
2) If lookbehind is not supported then you can do as:
/"[^"] /
const str = `?poll "<title>" "<choice>" "<choice>"`;
const result = str
.match(/"[^"] /g)
.map((s) => s.slice(1))
.filter((s) => s.trim());
console.log(result);