JonatanEkstedt
JonatanEkstedt

Reputation: 925

Regex matching a string followed by anything but a certain character

Regex match every char but the following
This didn't help me.

I'm trying to match momentaneousVehicleSpeedKmph= followed by anything but 9 in a gz file.

These don't match:

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

This does:

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

I now there're lines in the file containing momentaneousVehicleSpeedKmph=89.

Upvotes: 1

Views: 1988

Answers (1)

EverythingRightPlace
EverythingRightPlace

Reputation: 1197

simply try

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

if you don't want to match the single 9.

/edit

If you also need speeds with 2 digits and more, try:

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

Upvotes: 1

Related Questions