public Regex FileElementRegex = new Regex( "(?:(?<commandId>\\d*)|<value>(?<Values>\\w*)</value>)", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.ExplicitCapture | RegexOptions.CultureInvariant | RegexOptions.Compiled );
Regex FileElementRegex = new Regex( "(?: (?<commandId>\\d*) |<value>(?<Values>\\w*)</value>)", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.ExplicitCapture | RegexOptions.CultureInvariant | RegexOptions.Compiled ); MatchCollection matches = FileElementRegex.Matches(file); // Report on each match. foreach (Match match in matches) { GroupCollection groups = match.Groups; if (groups["commandId"].Success) Console.WriteLine(groups["commandId"].Value); if (groups["Values"].Success) Console.WriteLine(groups["Values"].Value); }
Regex FileElementRegex = new Regex( "(?: (?<commandId>\\d*) | \r\n<name>(?<name>\\w"+ "*)</name> \r\n<value>(?<Values>\\w*)</value> \r\n )", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.CultureInvariant | RegexOptions.Compiled ); MatchCollection matches = FileElementRegex.Matches(file); // Report on each match. foreach (Match match in matches) { GroupCollection groups = match.Groups; if (groups["commandId"].Success) Console.WriteLine("Commande: {0}",groups["commandId"].Value); if (groups["name"].Success) Console.WriteLine("Name: {0} Value: {1}", groups["name"].Value, groups["Values"].Value); }