Confusing but two solutions:
.split()
var lines = myText.split('\n'); //Splits lines
if (lines[0].toLowerCase().indexOf('red') > -1) { // Checks if 0th (1st line) contains 'red'
alert("Red!");
}
Read text after is
var noun = 'apple',
lines = myText.split('\n');
if (lines[0].match(new RegExp(noun+'\s*is\s*\b(\w+?)\b', 'i'))[1] === 'red') {
alert('Red!');
}
Basic answer
You can split a text into lines using: .split('\n')
. Example
var lines = multiLineTextString.split('\n');
Now in JavaScript, lines
will start at zero so the first line will be 0
the second 1
, etc. So to select it:
line[0] === 'red'
This will be true if the text of the first line is red