Reputation: 751
I am working with a text such as this:
Graham, Mckenna -- ut Voluptatem ipsam et at.Marvin, Garfield -- non Facere et necessitatibus animi. McLaughlin, Mariah -- consequatur Eveniet temporibus ducimus amet eaque. Lang, Agustina -- pariatur
As you can see, valid English names are separated by comma and a space. I am looking for a regular expression pattern to extract such substring. Comma should be included in the substring but not the trailing white space. I haven't had much luck in finding the correct pattern yet.
my code in C# looks like this:
var value = reader.ReadLine();
var regex = new Regex(@"[A-Z]\w+,(?=\s)");
var match = regex.Match(value);
Upvotes: 1
Views: 65
Reputation: 70722
If you are trying to match the names before the comma and after the comma, you can use the following.
var rgx = new Regex(@"[A-Z][a-zA-Z]+, *[A-Z][a-zA-Z]+");
Or you could simplify the pattern to the following in this case:
var rgx = new Regex(@"(?i)[a-z]+, *[a-z]+");
Upvotes: 2