我正在尝试收集所有匹配项,然后循环遍历它们以获得正确的结果。当我循环时,我只获得第一个捕获
04:04:01.121
set fileData "here is more stuf
04:04:01.121 Found Me 1
this is nothing
04:04:01.122 Found Me 2
this is nothing 1
04:04:01.123 Found Me 3
this is nothing 2
04:04:01.124 Found Me 4
this is nothing 3
04:04:01.125 Found Me 5
this is nothing 4
04:04:01.126 Found Me 6"
set testRegEx "(\\d{2}:\\d{2}:\\d{2}.\\d{3}).*Found Me"
set regexList [regexp -nocase -all -inline $testRegEx $fileData]
foreach {whole item} $regexList {
puts "-----$item"
}
像
*
这样的重复运算符是贪婪;他们尽可能匹配。所以你的 RE 匹配开头的 04:04:01.121
和最后一个 Found Me
,其他所有内容都被 .*
消耗。
尝试:
set testRegEx "(\\d{2}:\\d{2}:\\d{2}.\\d{3}) Found Me"
相反。