0

当我使用 javascript 正则表达式时,它工作正常,但 Regex.Matches 只返回 1 个匹配项,即初始字符串。

这是正则表达式

(\d+)(?:\s*)(?:([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4}))(?:\s*)(?:\w*)(?:\s*)(.*)

这是示例字符串,我尝试解析

  50    0000.74b9.ed90    DYNAMIC     Gi0/20
4

1 回答 1

2

尝试使用匹配而不是匹配。索引 [0] 是整个匹配。

Regex.Match("50    0000.74b9.ed90    DYNAMIC     Gi0/20", @"(\d+)(?:\s*)(?:([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4}))(?:\s*)(?:\w*)(?:\s*)(.*)").Groups[1].ToString()

Regex.Match(input,regex).Groups[1].ToString()
Regex.Match(input,regex).Groups[2].ToString()
Regex.Match(input,regex).Groups[3].ToString()
....
于 2013-10-18T07:02:00.810 回答