简体   繁体   English

Python正则表达式搜索中/日字符

[英]Python Regex Search Chinese/Japanese Characters

Aside from using the Unicode mode (http://xahlee.org/perl-python/regex_split.html) in Python to search Chinese/Japanese characters, is it possible to still search for the said character in case insensitive or sensitive mode? 除了在Python中使用Unicode模式(http://xahlee.org/perl-python/regex_split.html)来搜索中文/日文字符外,是否可以在不区分大小写或敏感的模式下搜索所述字符? (re.i) (re.i)

I'm trying to understand why the following do not work: 我试图了解以下原因为何不起作用:

mystring = 你是我
found    = re.search(你是我, mystring, re.I)
found    = re.search(你是我, mystring)

Chinese and Japanese characters don't have a case, so they are unaffected by the case insensitivity flag. 中文和日语字符没有大小写,因此不受大小写不敏感标志的影响。 Make sure you are using unicode strings though. 但是请确保使用的是unicode字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM