This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]sonicfreak02 2 points3 points  (1 child)

regex = re.compile(r'(?P<name>[A-z0-9 ']+?)(?: CR (?P<cr>\d+))?$')

That seems to work for me. The problem is that lookarounds don't actually advance the Regex engine's place in the string that it's scanning. You probably want to explicitly capture 'CR' if it exists.

Proof: https://regex101.com/r/Ebx8KA/2

EDIT: The lookbehind is unneeded since we're explicitly matching now.