Actually, there is a pattern that works, but there is a problem, I just can not figure out how to get everything from the first group.

var r = new Regex(@"^himikogp?:\/\/*(\/[\w- ./?%&=]*\/\w+\/)*([{0-9}]\w+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); var m = r.Match(command); 

Here is the line from which we get the groups: himikogp://install/app/987 I would like to form an IList<string> from the groups, or an array of strings. Thank.

    1 answer 1

    You need to use the Matches method of the Regex class and organize a loop on the result that it returns:

     string pattern = "^himikogp?:\/\/*(\/[\w- ./?%&=]*\/\w+\/)*([{0-9}]\w+)$"; foreach (Match match in Regex.Matches(command, pattern, RegexOptions.IgnoreCase)) Console.WriteLine("{0} at position {1}", match.Value, match.Index); 

    Instead of Console.WriteLine you do what you need, that is, you add to the array match.Value .

    • True, the code has become a bit creepy in appearance, since castes to ToArray did not work - Mikhail Himiko