| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Text.RegularExpressions; |
| | | 3 | | |
| | | 4 | | namespace WireMock.Util |
| | | 5 | | { |
| | | 6 | | internal static class RegexUtils |
| | | 7 | | { |
| | | 8 | | public static Dictionary<string, string> GetNamedGroups(Regex regex, string input) |
| | 3 | 9 | | { |
| | 3 | 10 | | var namedGroupsDictionary = new Dictionary<string, string>(); |
| | | 11 | | |
| | 3 | 12 | | GroupCollection groups = regex.Match(input).Groups; |
| | 27 | 13 | | foreach (string groupName in regex.GetGroupNames()) |
| | 9 | 14 | | { |
| | 9 | 15 | | if (groups[groupName].Captures.Count > 0) |
| | 3 | 16 | | { |
| | 3 | 17 | | namedGroupsDictionary.Add(groupName, groups[groupName].Value); |
| | 3 | 18 | | } |
| | 9 | 19 | | } |
| | | 20 | | |
| | 3 | 21 | | return namedGroupsDictionary; |
| | 3 | 22 | | } |
| | | 23 | | } |
| | | 24 | | } |