我的字符串如下:
如何使用正则表达式从不包含任何数字的字段c中提取值?我试过像:
r"\"filed c\"\:\"([^\"\d]*)"
但它没有用。谢谢。
答案 0 :(得分:0)
说你有,
records = [
'"record one","field a":"random a b c","filed b":"random a b c","filed c":"123"',
'"record two","field a":"random a b c","filed b":"random a b c","filed c":"abc"',
'"record ...","field a":"random a b c","filed b":"random a b c","filed c":"ab12c"',
'"record ...","field a":"random a b c","filed b":"random a b c","filed c":""',
'"record ...","field a":"random a b c","filed b":"random a b c","filed c":"12abc"',
'"record nth","field a":"random a b c","filed b":"random a b c","filed c":"Xyz"',
]
做什么
import re
rex = '"filed c":"([^\d]*)"'
does_not_contain_any_number = []
for record in records:
q = re.compile(rex, re.DOTALL).findall(record)
if len(''.join(q)):
does_not_contain_any_number += q
print(does_not_contain_any_number)
#['abc', 'Xyz']