Python Regex stop on string
<p>So I want to search using regex for seasons which are not followed by episode number and I have the following list :</p>

<pre><code>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']
</code></pre>

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

<p>From previous experience, I'd suggest not solely doing this with regex, but I've quickly thrown together the following snippet (after which no_episode_string will contain all of the ones without episodes).</p>

<p>For each season we match against ".<em>?[0-9]</em>(.*)", which simply grabs everything up to and including the first time we encounter a number, and then take the rest of the string, which will either be empty (if there is no episode number), or non-empty if there is an episode number. </p>

<p>So we just check whether it is empty or not, and if it is, then we add the whole thing to no_episode_string.</p>

<pre><code>import re

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

no_episode_string = []

for season in string: 
    m = re.search('.*?[0-9]+(.*)', season)
    if m.group(1) == "":
        no_episode_string.append(m.group(0))
</code></pre>

python regex