Regex and unicode

前端 未结 4 517
死守一世寂寞
死守一世寂寞 2020-12-03 04:51

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

相关标签:
4条回答
  • 2020-12-03 05:17

    Python's re module doesn't support \p{Letter} or \X. However, the new regex implementation on PyPI does.

    0 讨论(0)
  • 2020-12-03 05:23

    \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.

    0 讨论(0)
  • 2020-12-03 05:29

    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.

    0 讨论(0)
  • 2020-12-03 05:42

    Use a subrange of [\u0000-\uFFFF] for what you want.

    You can also use the re.UNICODE compile flag. The docs say that if UNICODE is set, \w will match the characters [0-9_] plus whatever is classified as alphanumeric in the Unicode character properties database.

    See also http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-05/2560.html.

    0 讨论(0)
提交回复
热议问题