I'm trying to write a regex with named captures in C# to parse cron jobs. The problem, however, is that both using single quote and bracket named capture groups the values return blank. For example, with the input
*/15 * * * * * http://www.google.com/
this code:
Regex cronRe = new Regex(@"(?<minutes>[\d\*\-,]+) (?<hours>[\d\*\-,]+) (?<days>[\d\*\-,]+) (?<months>[\d\*\-,]+) (?<dotw>[\d\*\-,]+) (?<years>[\d\*\-,]+) (?<command>[\d\*\-,]+)");
//loop through jobs and do them
for (int i = 0; i < lines.Length; i++)
{
Match line = logRe.Match(lines[i]);
bool runJob = true;
for (int j = 0; j < line.Groups.Count; j++)
{
Console.Write(j.ToString() + ": " + line.Groups[j].Value + "\n");
}
Console.Write("named group minutes: " + line.Groups["minutes"].Value);
}
return with this:
0: */15 * * * * * http://www.google.com
1: */15 *
2: * 3: *
4: *
5: *
6: http://www.google.com
named group minutes:
any suggestions?