How can I convert the list of match result from regex into List
? I have this function but it always generate an exception,
A possible solution using Linq:
using System.Linq;
using System.Text.RegularExpressions;
static class Program {
static void Main(string[] aargs) {
string value = "I have a dog and a cat.";
Regex regex = new Regex("dog|cat");
var matchesList = (from Match m in regex.Matches(value) select m.Value).ToList();
}
}