开发者

Confusion on expr usage

开发者 https://www.devze.com 2023-03-15 05:36 出处:网络
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.\"

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

精彩评论

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