David Green David Green - 1 month ago 6
C# Question

Pattern Is Matching Every Other Line Of Input

Here is the pattern I have:

\s+\d+:\s+(?<local>\d+)[-][>]\s+?(?<remote>\d+)\s+(?<wwn>..:..:..:..:..:..:..:..)\s+\d+\s+(?<name>\w+)\s+[s][p]:\s+\w+.\w+\s+\w+[:]\s+\d.\w+\s+(?<trunk>TRUNK)?


Here is the input. The '*' is not part of the input, it's just designating what is matched. I'm testing this at RegExStorm.net. I don't think the every other line is significant by itself, different input didn't follow with matching every other line. I can't see what's different, if anything between the matched and non-match lines except for the line that says QOS but the match should still succeed there, it would just throw that away.

* 1: 0-> 11 10:00:00:05:1e:89:ed:8c 14 SAN009B sp: 8.000G bw: 8.000G
2: 23-> 2 50:00:51:e8:b9:1b:ae:01 3 fcr_fd_3 sp: 8.000G bw: 8.000G
* 3: 24-> 22 10:00:00:05:1e:36:5b:ea 1 SAN001B sp: 4.000G bw: 4.000G TRUNK
4: 38-> 38 10:00:00:05:1e:e2:45:00 9 SAN004B sp: 8.000G bw: 24.000G TRUNK QOS
*5: 48-> 15 10:00:00:05:1e:89:ed:8c 14 SAN009B sp: 8.000G bw: 8.000G
6: 49-> 10 10:00:00:05:1e:87:5a:e4 13 SAN013B sp: 8.000G bw: 8.000G
*7: 56-> 3 10:00:00:05:1e:84:15:dc 11 SAN011B sp: 8.000G bw: 8.000G
8: 64-> 16 10:00:00:05:1e:89:ed:8c 14 SAN009B sp: 8.000G bw: 8.000G
* 9: 65-> 18 10:00:00:05:1e:87:5a:e4 13 SAN013B sp: 8.000G bw: 8.000G
10: 72-> 63 10:00:00:05:1e:84:15:dc 11 SAN011B sp: 8.000G bw: 8.000G
*11: 87-> 27 50:00:51:e8:b9:1b:ae:01 3 fcr_fd_3 sp: 8.000G bw: 8.000G

Answer

That's because of this part: \d.\w+

The corresponding part for the other number is \w+.\w+

24 (from the 24.000G substring) does not fit the \d, so you either should use \d+ or \w+.

Another note, in this excerpt it you want to use the dot literal as-is, you need to escape it as \., since otherwise it matches any character.

How I found your problem: I opened it on https://regex101.com/ and removed the parts from the regular expression until it matched, then it was immediately obvious.