Prixeler Prixeler - 1 year ago 132
Python Question

Python Regex stop on string

So I want to search using regex for seasons which are not followed by episode number and I have the following list :

string = ['Fear the walking dead Season 2 Episode 9',
'Veep Season 5',
'Martine Season 2 (unknown number of episodes)',
'New Girl Season 5 Episode 16']

I've written this code'.+? Season [0-9]{1,2}', string, re.I)
but it seems to take into consideration the series with an episode number also.
I want it to return True only on
Veep Season 5

Answer Source

I would recommend using ^ and $ to match from the beginning of a line to the end. So you can change your regex to:'^(.+?Season\s[0-9]{1,2})$', string, re.I | re.M)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download