I need a regex that captures 2 groups: a movie and the year. Optionally, there could be a 'from ' string between them.
My expected results are:
first_query="matrix 2013" => ('matrix', '2013')
second_query="matrix from 2013" => ('matrix', '2013')
third_query="matrix" => ('matrix', None)
I've done 2 simulations on https://regex101.com/ for python3:
I- r"(.+)(?:from ){0,1}([1-2]\d{3})"
Doesn't match first_query and third_query, also doesn't omit 'from' in group one, which is what I want to avoid.
II- r"(.+)(?:from ){1}([1-2]\d{3})"
Works with second_query, but does not match first_query and third_query.
Is it possible to match all three strings, omitting the 'from ' string from the first group?
Thanks in advance.