'finding the first instance of a 10 digit number after a different search parameter in python using regex

I have a binary file in which I need to find if it contains a error message "MCPS" and if it does, I need to find first instance of a 10 digit number after that message (note this will eventually be used for a list of files rather than 1 but I need to walk before I run). I am using the following code to open the file and then want to use a regex to search through the file.

with open('file.20_txt', 'rb') as f:
    s=f.read()

searchparam=re.compile(b"MCPS[\s\S]*\d{10}")
result=re.search(searchparam,s)
print(result)

since the characters between "MCPS" and the first occurrence of a 10 digit number are not always the same and often contain line changes I am trying to use "MCPS[\s\S]*\d{10}" using the suggestion of another thread (the "[\s\S]" rater than "." to get around white spaces) to get a desired output of MCPS + any number of characters(including white space) + first 10 digit number. What I get with the code above is MCPS + any number of characters(including white space) + the last 10 digit number of the file. note i am using python 3 for this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source