It should be very simple, but I cannot figure out, how to match the beginning and the end of a multiline string. Say, I want to know, whether the string contains foo
at the beginning of the first line.
str = "foo\nbar";
reg = /^foo/m;
console.log( reg.test( str ) ); // → true
But if I swap foo
and bar
, thus placing foo
in the second line, the result will (though shouldn't) be the same:
str = "bar\nfoo";
reg = /^foo/m;
console.log( reg.test( str ) ); // → true
So, is there a way to catch the beginning and the end of a multiline string?