$我正在尝试使用具有以下条件的正则表达式提取 TCL 中的特定单词
设置标题“保留给KNBCDEF-ABCD01” 设置 greptitle [regexp -all -inline {\mK[AHNZR][A-Za-z]*-[0-9]{2}\M} $title] send_user "匹配模式:$greptitle ”
尝试上面的代码,但输出为空。
从字符串中提取的单词可以采用以下任何格式,只要符合上述条件即可 KNBCDEF-ABCD01 或 KAXXG-YYUU54 或 KRBEF-ZZ654 等
你几乎是正确的,你不需要在
\m
模式中使用 \M
或 regexp
set title "reserved for KNBCDEF-ABCD01"
set greptitle [regexp {\s+K[AHNZR]\w+-\w+\d\d} $title match]
如果模式匹配,则
greptitle
包含 1,否则 0
puts "Matched patterns: $greptitle\n"
match
有你的图案
puts $match