开发者

Confusion on expr usage

expr manual page says: "Pattern matches return the string matched between ( and ) or null; if ( and ) are not used, they return the number of characters matched or 0."

I am doing

echo `expr 开发者_StackOverflow中文版ABCDEF : ABC`

which gives 3 as expected

However, this also gives 3, why ?

echo `expr \( ABCDEF : ABC \)`


There are two different kinds of parentheses there; the ones you used are part of the expression syntax, whereas your quote is about regular expression parentheses within the pattern.

expr \( ABCDEF : ABC \) # parenthesized expression
expr ABCDEF : \(ABC\) # capturing parentheses in pattern
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜