2013-04-27 32 views

回答

4

man頁的expr版本不是很清楚:

STRING : REGEXP 
      anchored pattern match of REGEXP in STRING 

match STRING REGEXP 
      same as STRING : REGEXP 

究竟什麼不「掛靠」是什麼意思? BSD版清除的東西了:

正則表達式錨定到 開始與一個隱含的``^「」的字符串。

所以expr match "234can't find" 'c'是相同的expr match "234can't find" '^c',由於您的字符串不開始c,匹配失敗。


由於bash支持正則表達式匹配本身,你可以贊成

[[ "234can't find" =~ c ]] 
+0

放棄expr命令你救我,chepner。 – 2013-04-27 11:51:30