无法检测到该字符串是 "c++ comment"
Can't detect that string is "c++ comment"
我尝试使用 tcl 在 c++
代码文件中查找注释,但我在使用 regexp
时遇到了问题
set str "\ads dsa dsad s s s s "
set result [regexp { ^\\ } $str]
puts "result = $result"
它打印:result = 0
,但我不明白为什么。
大括号中的字符串是固定的。您正在尝试查找“(space)^\\(space)
”的匹配项。我相信您想使用这样的东西:
set result [regexp {^\s*\\} $str]
此外,您的样本字符串错误。由于双引号,反斜杠将被合并。
我相信您想使用这样的东西:
set str "\\ads dsa dsad s s s s "
或
set str {\ads dsa dsad s s s s }
我尝试使用 tcl 在 c++
代码文件中查找注释,但我在使用 regexp
set str "\ads dsa dsad s s s s "
set result [regexp { ^\\ } $str]
puts "result = $result"
它打印:result = 0
,但我不明白为什么。
大括号中的字符串是固定的。您正在尝试查找“(space)^\\(space)
”的匹配项。我相信您想使用这样的东西:
set result [regexp {^\s*\\} $str]
此外,您的样本字符串错误。由于双引号,反斜杠将被合并。 我相信您想使用这样的东西:
set str "\\ads dsa dsad s s s s "
或
set str {\ads dsa dsad s s s s }