So, I have a string and I want to return an entire line when that line contains the word I'm searching for. I have this code:
var subtitle = '4'+
'00:00:24.067 --> 00:00:35.924'+
'Hi, how are you?'+
'Doing fine?'+
''+
'5'+
'00:00:35.926 --> 00:00:47.264'+
'I\'m doing the best I can.'+
'And you?';
var myRe = /^.* you.*$/ig;
var myArray;
while ((myArray = myRe.exec(legenda)) !== null) {
var msg = 'Found ' + myArray[0] + '. ';
msg += 'Next match starts at ' + myRe.lastIndex;
console.log(msg);
}
In the code above I'm trying to return the two lines that contain the word "you", the expected output would be: "Hi, how are you?" and "And you?" but I'm getting all the content of the subtitle variable. But, if I check my regular expression here I'm getting the desired output.
Could somebody help me, please? It's my first time using regular expressions and I'm feeling a bit lost.