I want to learn a bit about regular expressions. I have a String that represents the Vehicle Identification Number (VIN) in hexadecimal code.
The problem is, that the string will have a different pattern, depending on the car I am using to get it.
The first pattern is the following (spaces and newlines only for better visibility):
49 02 01 00 00 00 xx
49 02 02 xx xx xx xx
49 02 03 xx xx xx xx
49 02 04 xx xx xx xx
49 02 05 xx xx xx xx
Where xx
are the bytes containing the data. As you can see, the data consists of 17 characters.
The second pattern that the car might return is the following (spaces and newlines only for better visibility):
014
0: 49 02 01 xx xx xx
1: xx xx xx xx xx xx xx
2: xx xx xx xx xx xx xx
Where xx
are the bytes containing the data. As you can see, the data also consists of 17 characters.
I only want to read the xx
part, and concatenate the result to a string that I will decode with str.decode("hex")
to get my VIN.
So, my question is: is it possible to pack all this in a regular expression to get the final 17 bytes as result?