[i=s] 本帖最后由 Guin 于 2011-5-19 12:31 编辑 [/i]
标题这个表达式,介绍说是返回匹配的子串,测试并非如此:
If the match succeeds and REGEX uses `\(' and `\)', the `:'
expression returns the part of STRING that matched the
subexpression; otherwise, it returns the number of characters
matched.
$ expr abcd : \( abc \)
3
$ expr abcd : abc
3
何故?
括号必须引用:
$ expr abcd : '\(abc\)'
abc