2013-08-26 99 views
1

Regex match every char but the following
這並沒有幫助我。正則表達式匹配一個字符串後跟除某個字符之外的任何東西

我試圖匹配momentaneousVehicleSpeedKmph=後面除9之外的任何一個gz文件。

這些不匹配:

$zgrep "momentaneousVehicleSpeedKmph=\[\^9\]" file.gz 
$zgrep "momentaneousVehicleSpeedKmph=\(\^9\)" file.gz 
$zgrep "momentaneousVehicleSpeedKmph=\^\[9\]" file.gz 
$zgrep "momentaneousVehicleSpeedKmph=\^\(9\)" file.gz 

這並不:

$zgrep "momentaneousVehicleSpeedKmph=\(9\)" file.gz 

我現在也正在文件中的行包含momentaneousVehicleSpeedKmph=89

回答

1

只是一味

$zgrep "momentaneousVehicleSpeedKmph=[^9]" file.gz

,如果你不想匹配的單9

/編輯

如果您還需要2個位數甚至更高的速率,嘗試:

momentaneousVehicleSpeedKmph=([0-8]|[0-9]{2,})\b

+0

哦,尷尬!我以爲你必須逃避他們。謝謝! – JonatanEkstedt

相關問題