<p>I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example), grabs the episode name (from the www.thetvdb.com API) and automatically renames them into something nicer (Show Name - [01x02].avi)</p>

<p>The script works fine, that is until you try and use it on files that have Unicode show-names (something I never really thought about, since all the files I have are English, so mostly pretty-much all fall within <code>[a-zA-Z0-9'\-]</code>)</p>

<p>How can I allow the regular expressions to match accented characters and the likes? Currently the regex's config section looks like..</p>

<pre><code>config['valid_filename_chars'] = """0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@£$%^&amp;*()_+=-[]{}"'.,&lt;&gt;`~? """
config['valid_filename_chars_regex'] = re.escape(config['valid_filename_chars'])

config['name_parse'] = [
    # foo_[s01]_[e01]
    re.compile('''^([%s]+?)[ \._\-]\[[Ss]([0-9]+?)\]_\[[Ee]([0-9]+?)\]?[^\\/]*$'''% (config['valid_filename_chars_regex'])),
    # foo.1x09*
    re.compile('''^([%s]+?)[ \._\-]\[?([0-9]+)x([0-9]+)[^\\/]*$''' % (config['valid_filename_chars_regex'])),
    # foo.s01.e01, foo.s01_e01
    re.compile('''^([%s]+?)[ \._\-][Ss]([0-9]+)[\.\- ]?[Ee]([0-9]+)[^\\/]*$''' % (config['valid_filename_chars_regex'])),
    # foo.103*
    re.compile('''^([%s]+)[ \._\-]([0-9]{1})([0-9]{2})[\._ -][^\\/]*$''' % (config['valid_filename_chars_regex'])),
    # foo.0103*
    re.compile('''^([%s]+)[ \._\-]([0-9]{2})([0-9]{2,3})[\._ -][^\\/]*$''' % (config['valid_filename_chars_regex'])),
]
</code></pre>

[{'answer_id': 14391, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 5, 'selected': True, 'text': '<p>Use a subrange of <code>[\\u0000-\\uFFFF]</code> for what you want.</p>\n\n<p>You can also use the <code>re.UNICODE</code> compile flag. <a href="http://docs.python.org/lib/re-syntax.html" rel="nofollow noreferrer">The docs</a> say that if <code>UNICODE</code> is set, <code>\\w</code> will match the characters <code>[0-9_]</code> plus whatever is classified as alphanumeric in the Unicode character properties database. </p>\n\n<p>See also <a href="http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-05/2560.html" rel="nofollow noreferrer">http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-05/2560.html</a>.</p>\n'}, {'answer_id': 14399, 'author': 'grapefrukt', 'author_id': 914, 'author_profile': 'https://Stackoverflow.com/users/914', 'pm_score': 0, 'selected': False, 'text': '<p>\\X seems to be available as a generic word-character in some languages, it allows you to match a single character disregarding of how many bytes it takes up. Might be useful.</p>\n'}, {'answer_id': 14420, 'author': 'Peter Stuifzand', 'author_id': 1633, 'author_profile': 'https://Stackoverflow.com/users/1633', 'pm_score': 2, 'selected': False, 'text': '<p>In Mastering Regular Expressions from Jeffrey Friedl (great book) it is mentioned that you could use \\p{Letter} which will match unicode stuff that is considered a letter.</p>\n'}, {'answer_id': 5519872, 'author': 'MRAB', 'author_id': 688213, 'author_profile': 'https://Stackoverflow.com/users/688213', 'pm_score': 3, 'selected': False, 'text': '<p>Python\'s re module doesn\'t support \\p{Letter} or \\X. However, the <a href="http://pypi.python.org/pypi/regex" rel="noreferrer">new regex implementation on PyPI</a> does.</p>\n'}]
['https://Stackoverflow.com/questions/14389', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/745/']