我有一个以下格式的文件:
some text
some more text
. . .
. . .
data {
1 2 3 5 yes 10
2 3 4 5 no 11
}
some text
some text
我想data
通过以下过程使用正则表达式提取文件的一部分:
proc ExtractData {fileName} {
set sgd [open $fileName r]
set sgdContents [read $sgd]
regexp "data \\{(?.*)\\}" $sgdContents -> data
puts $data
}
但这给出了以下错误:
couldn't compile regular expression pattern: quantifier operand invalid
我无法弄清楚正则表达式有什么问题。任何帮助将不胜感激。
使用此正则表达式
regexp {data \{(.*)\}} $sgdContents wholematch submatch
puts $submatch
wholematch
匹配整个模式。你的情况是
data {
1 2 3 5 yes 10
2 3 4 5 no 11
}
并且submatch
仅匹配括号内的内容,如下所示:
1 2 3 5 yes 10
2 3 4 5 no 11
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句