private PathFinder MakePathFinder(string graph) { var pf = new PathFinder(); var edgePattern = new Regex("(\\D+)(\\D+)(\\d+)"); var edges = graph.Split(','); foreach (var edge in edges) { if (edgePattern.IsMatch(edge)) { var begin = edgePattern.Replace(edge, "$1"); var end = edgePattern.Replace(edge, "$2"); var length = int.Parse(edgePattern.Replace(edge, "$3")); pf.AddEdge(begin, end, length); } } pf.FindPath("A", "Z"); return(pf); }