红联Linux门户
Linux帮助

[Debian] expr string : \( regex \)

发布时间:2011-05-19 09:20:25来源:红联作者:Guin
[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
文章评论

共有 0 条评论