【发布时间】:2018-08-16 04:47:59
【问题描述】:
我正在尝试使用正则表达式搜索文件夹中的文件,但是当我尝试在变量中传递正则表达式时
file_to_search = re.search('Weekly' +(\d{2})[/.-](\d{2})[/.-](\d{4})$ + 'Scores.xlsx')
我要搜索的文件模式是
每周 02.28.2018 Scores.xlsx
每周 03.05.2018 Scores.xlsx
到目前为止,我不在乎文件是否为:
每周 99.99.9999 分数.xlsx
但我得到以下错误指向行尾。
SyntaxError: unexpected character after line continuation character.
file_to_search = re.search('Weekly' +\d{2}\d{2}\d{4}+ 'Scores.xlsx')
^
【问题讨论】:
-
(\d{2})[/.-](\d{2})[/.-](\d{4})$不是有效的表达式。正则表达式在 Python 中被写成字符串。你特地把它排除在你的字符串之外。 -
想知道
startswith()和endswith()吗?
标签: python regex python-2.7 regex-group