重新匹配在python中匹配模式和字符串

2024-09-27 09:21:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将stringmypattern匹配,但不知何故我没有得到正确的结果。你能指出我哪里错了吗?你知道吗

import re
mypattern = '_U_[R|S]_data.csv'
string =  'X003_U_R_data.csv'
re.match(mypattern, string)

Tags: csvimportredatastringmatchx003mypattern
1条回答
网友
1楼 · 发布于 2024-09-27 09:21:53

我喜欢先编译regex语句。然后我做任何我想做的匹配/搜索。你知道吗

mypattern = re.compile(ur'_U_[R|S]_data.csv')

那么

re.search(mypattern, string)

这里有一个很好的regex创建网站-https://regex101.com/#python

相关问题 更多 >

    热门问题