The challenge I need to resolve is getting a sub-string from strings such as those below. Each line is of an array so I am iterating and working on one line at a time in a JavaScript loop. All of the strings have the names at the start of the line:
Joe Smith will run...
Jane Jones will follow...
Bridget Burns and Jack Jones will be away...
Jack Jones, Gracie Burns and George Burns have three days in...
The sub-string I need is the name(s) at the start of each string. My JavaScript is handling an example of the first or second line adequately by:
substr = replace(/^(\w+ \w+ )(?:.*)/g,"$1").trim();
will output Joe Smith
or Jane Jones
respectively.
Is there a method to extract just the names, preferably as one variable?
I have some experience with regular expressions but not enough to reliably extract what I need from examples such as these.