Hyphen at beginning of regex causes it to stop matching (python 2.7) - but at the end it's fine?
<p>I'm writing a simple script to dump the tracks, artists, and times of a bandcamp album (<a href="https://nihonkizuna.bandcamp.com/album/nihon-kizuna" rel="nofollow">https://nihonkizuna.bandcamp.com/album/nihon-kizuna</a>), but I'm having trouble with the regex. For context, the track titles are in the format "Artist - Title". I'm trying to separate the dumped track titles so that I have the artist in one list and the title in another, then writing these and the time to a csv.</p>

<p>For some reason, the expression:</p>

<pre><code>(.*) -
</code></pre>

<p>Finds the artist correctly, but:</p>

<pre><code>- (.*)
</code></pre>

<p>Fails to find the title correctly. Instead I get:</p>

<pre><code>AttributeError: 'NoneType' object has no attribute 'group'
</code></pre>

<p>I've tried escaping the hyphen, but python returns "None" for a match as long as it's the first character. I've tried testing it by regexing an actual title, "- 9 Samurai", and it still fails.</p>

<pre><code>import pandas as pd
from lxml import html
import re
import requests

page = requests.get("https://nihonkizuna.bandcamp.com/album/nihon-kizuna")
tree = html.fromstring(page.content)

tracks = tree.xpath('//table[@id ="track_table"]//td[@class="title-col"]/div[@class="title"]/a/span/text()')
time = tree.xpath('//table[@id ="track_table"]//td[@class="title-col"]/div[@class="title"]/span/text()')
newtimes = []
artists = []
newtracks = []

for item in time:
    newitem = item.strip()
    newtimes.append(newitem)

for item in tracks:
    track_item = re.match("(.*) -", item)
    artists.append(track_item.group(1))
    newitem2 = re.match("- (.*)", item)
    newtracks.append(newitem2.group(1))

raw_data = {"track": newtracks, "artist": artists, "time": newtimes}

df = pd.DataFrame(raw_data, columns = ["track", "artist", "time"])
df.index += 1

df.to_csv(raw_input("Input the csv path."))
</code></pre>

<p>Why don't use a regular <a href="https://docs.python.org/2/library/stdtypes.html#str.split" rel="nofollow"><code>str.split()</code></a>:</p>

<pre><code>artists, newtracks = zip(*[item.split(" - ") for item in tracks])
</code></pre>

<p>The <code>zip(*[...])</code> here would <em>unzip</em> the list of 2-item tuples into two separate sequences allowing us to separate artists and newtracks.</p>

<hr>

<p>Note that both solutions are vulnerable <em>in case a dash can be a part of artist or track name</em>. On this particular page, artist and track names are always met "together", joined with <code>-</code>. If you are worried about cases like these and you can sacrifice performance in exchange for quality and robustness - <em>follow the track pages</em> where you have artists and songs defined separately. If you do that, make sure to have a <a class='doc-link' href="http://stackoverflow.com/documentation/python/1792/web-scraping-with-python/8152/maintaining-web-scraping-session-with-requests#t=201609081605531690323">web-scraping <code>requests</code> session</a> defined while you crawl the website.</p>

python regex python-2.7