Вот пример, показывающий, как вы можете подойти к этому.
1) Учитывая эту входную строку:
const inputText =
`Text:"How secure is my information?"someRandomTextHere
Voice:"Not very much"
Text:"How to improve this?"
Voice:"Don't use '123456' for your password"
Text:"OK just like in the "Hackers" movie."`;
2) Извлекать данные в двойных кавычках после литерала Text:
, чтобы результаты представляли собой массив со всеми совпадениями, например:
["How secure is my information?",
"How to improve this?",
"OK just like in the \"Hackers\" movie."]
РЕШЕНИЕ
function getText(text) {
return text
.match(/Text:".*"/g)
.map(item => item.match(/^Text:"(.*)"/)[1]);
}
console.log(JSON.stringify( getText(inputText) ));
РАБОТАЙТЕ, ЧТОБЫ УВИДЕТЬ РАБОЧИЙ ДЕМО
const inputText =
`Text:"How secure is my information?"someRandomTextHere
Voice:"Not very much"
Text:"How to improve this?"
Voice:"Don't use '123456' for your password"
Text:"OK just like in the "Hackers" movie."`;
function getText(text) {
return text
.match(/Text:".*"/g)
.map(item => item.match(/^Text:"(.*)"/)[1]);
}
console.log(JSON.stringify( getText(inputText) ));