I am looking for a specific string in text, and want to get it only if found.
I can write it as followד and it works:
if re.search("Counter=(\d+)", line):
total = int(re.search("Counter=(\d+)", line).group(1))
else:
total = 1
But I remember another nicer way to write it with question mark before the "group", and put value "1" as default value in case of re.search
return an empty result.