[英]How to search string using regular expression for string contains characters alphabets and special characters like -, () using python
I want to search dynamically some string contains case insensitive and some string contains special characters like (TM), (R) how to search those strings 我想动态搜索某些字符串不区分大小写,某些字符串包含特殊字符,例如(TM),(R)如何搜索那些字符串
with open(logfile) as inf:
for line in inf:
if re.search(string,line,re.IGNORECASE):
# print 'found line',line
I wanted to add re.IGNORECASE,re.escape() are giving error, How to solve it 我想添加re.IGNORECASE,re.escape()给出错误,如何解决
If i put this into python console... 如果我将其放入python控制台...
>>> re.search(re.escape("Stack(R) Overflow"), "Hey bro, Stack(R) Overflow", re.I)
<_sre.SRE_Match object at 0xb778adb0>
..i got correct result. ..我有正确的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.