无法在unicode字符串中使python的正则表达式忽略大小写.
mach = re.search(ur'(?P<mach>(?<=\s)%s(?=[\s\.]))' % u'????????', st, re.I | re.U)
Run Code Online (Sandbox Code Playgroud)
哪里
st = u" ????????... ???????? ?????????? ?? ??????. "
Run Code Online (Sandbox Code Playgroud)
注意这个词 - ?????????
我希望我的正则表达式能够找到这个词以及这个词 ????????
至今:
print mach
> None
Run Code Online (Sandbox Code Playgroud)
PS:现在每个人都可以开始减去我的问题了.它现在真的有效.即使从我的例子.但是,我花了一半的时间来解决这个问题.
你正在使用一个字符串st.这样它将unicode正则表达式与某些字节串匹配(取决于您的编码).使用unicode字符串:
st = u" ????????... ???????? ?????????? ?? ??????. "
print re.search(ur'(?P<match>(?<=\s)%s(?=[\s\.]))' % u'????????', st, re.I | re.U).groupdict()
# {u'match': u'\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c'}
Run Code Online (Sandbox Code Playgroud)