【发布时间】:2011-07-01 05:12:07
【问题描述】:
我想通过编写正则表达式来获取以 abc_ 或 xyz_ 开头的字符串中的单词。 这是我的脚本:
[regexp -nocase -- {.*\s+(abc_|xyz_\S+)\s+.*} $str all necessaryStr]
因此,如果我在 str1 和 str2 上应用上述编写的正则表达式,我想从 $str1 中获取“xyz_hello”,从 $str2 中获取“abc_bye”。
set str1 "gfrdgasjklh dlasd =-0-489 xyz_hello sddf 89rn sf n9"
set str2 "dytfasjklh abc_bye dlasd =-0tyj-489 sddf tyj89rn sjf n9"
但是我的正则表达式不起作用。我的问题是:
1) 我的正则表达式有什么问题? 2) 用正则表达式找一些预定义前缀开头的作品好还是用字符串函数(字符串匹配左右)更好?
【问题讨论】:
标签: regex string tcl string-matching