A regular expression with lookbehind
regex = /(?<=.*?:).*/g
can be used to produce an array with all matches found in the inputText
(from Piotr Berebecki's answer):
> inputText.match(regex)
[
'"How secure is my information?"someRandomTextHere',
'"Not very much"',
'"How to improve this?"',
`"Don't use '123456' for your password"`,
'"OK just like in the "Hackers" movie."'
]
Each match consists of the quoted string following the first colon in a line.
In the absence of lookbehinds, a regular expression with groups can be used:
regex = /(.*?:)(.*)/g
With this, each match consists of a complete line, with two groups: the first containing the part up to the colon and the second containing the rest.
> inputText.match(regex)
[
'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."'
]
To see the groups, you must use the .exec
method. The first match looks so:
> [...regex.exec(inputText)]
[
'Text:"How secure is my information?"someRandomTextHere',
'Text:',
'"How secure is my information?"someRandomTextHere'
]
To loop over all matches and process only the second group of each (that is, the part after the colon from each line), use something like:
> for (var m, regex = /(.*?:)(.*)/g; m = regex.exec(inputText); ) console.log(m[2]);
"How secure is my information?"someRandomTextHere
"Not very much"
"How to improve this?"
"Don't use '123456' for your password"
"OK just like in the "Hackers" movie."