Python regex not matching
<p>I am trying to extract a file name using regex. File names are in the list <code>files</code> , the pattern to be matched is <code>songTitle</code>. </p>

<pre><code> files = listdir(curdir)
        print("Pattern : %s" % songTitle)
        for songs in files:
            print(songs)
            re_found = re.match(re.escape(songTitle) + r'.*\.mp3$', songs)
            if re_found:
                FileName = re_found.group()
                print(FileName)
                break
</code></pre>

<p>In this example </p>

<p><code>files</code> contains :</p>

<pre><code>['.DS_Store', '__init__.py', 'command_line.py', "Skrillex &amp; Diplo - 'Mind' feat. Kai (Official Video)-fDrTbLXHKu8.mp3"]
</code></pre>

<p><code>songTitle</code> (Pattern to be matched) : <code>Skrillex &amp; Diplo - 'Mind' feat. Kai (Official Video)</code></p>

<p>Output : </p>

<pre><code>Pattern : Jack Ã - Take Ã There feat. Kiesza [OFFICIAL VIDEO]
.DS_Store
__init__.py
command_line.py
Jack Ã - Take Ã There feat. Kiesza [OFFICIAL VIDEO]-C9slkeFXogU.mp3
Skrillex &amp; Diplo - 'Mind' feat. Kai (Official Video)-fDrTbLXHKu8.mp3
</code></pre>

<p><strong>EDIT:</strong></p>

<p>I ran some tests and realised that the problem occurs due to non ascii characters. Such as the 'Ã' in this case.</p>

<p>This works:</p>

<pre><code>files = listdir(curdir)
print("Pattern : %s" % songTitle)
for songs in files:
    re_found = re.match(re.escape(songTitle) + r'.*\.mp3$', songs)
    if re_found:
        FileName = re_found.group()
        print(FileName)
        break
</code></pre>

python regex