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
精彩评论