1
s = "LEV606 (P), LEV230 (P)"
#Expected result: ['LEV606', 'LEV230']
# First attempt
In [3]: re.findall(r"[A-Z]{3}[0-9]{3}[ \(P\)]?", s)
Out[3]: ['LEV606 ', 'LEV230 ']
# Second attempt. The 'P' is not mandatory, can be other letter.
# Why this doesn't work?
In [4]: re.findall(r"[A-Z]{3}[0-9]{3}[ \([A-Z]{1}\)]?", s)
Out[4]: []
# Third attempt
# White space is still there. Why? I want to remove it from the answer
In [5]: re.findall(r"[A-Z]{3}[0-9]{3}[\s\(\w\)]?", s)
Out[5]: ['LEV606 ', 'LEV230 ']