我正在尝试使用python 3.6找出'('和此')'中的子字符串
正则表达式(?<=\()(.*?)(?=\))
可在https://regexr.com/中找到。
但是我无法在re.findall(r'(?<=\()(.*?)(?=\))',line,re.IGNORECASE)
中通过。它不能识别为字符串。如果我将\放在=的前面-会抛出这样的错误
TypeError: cannot use a string pattern on a bytes-like object
尝试这样的regexx
with open(name,'rb+') as f:
for line in f:
x= re.findall(r'[(?<=\()(.*?)(?=\))]',line,re.IGNORECASE)
#if matcm found - compare with other strings in list
print(x)
文件中的示例行:
a(name = somename)(add = some address)(location = someloacation)(zip = 000)(date = 01/01/1998 00:00)