My task is to find lines on a text file that match the following pattern: "SMC" followed by a space, 1-3 digits, period, and 1-3 digits. My issue: It's also returning digits after the second period/decimal.
import re
with open("caosDump.txt", 'r', encoding="cp1252") as inp, open("newCaosDump.txt", 'w') as output:
for line in inp:
if re.search(r'SMC\s\d{1,3}\.\d{1,3}', line):
output.write(line)
I have tried many things such as positive/negative lookahead, word boundary, etc. but nothing worked. Adding ^ and $ break the code.
It’s also returning the lines that contain SMC 14.08.040
, but I don’t want to include these lines on my new text file. (Note: Using Python)