我有一个字符串,看起来像这样:
";该公寓自2021年起出租给一名学生。每月租金为850欧元。额外费用为公用事业费(150欧元(">
我正在寻找与"0"非常接近(例如在20个字符内(的数值;租金;以及";欧元";。
我不想得到";2021";我不想得到";150〃-我想得到";850〃;。
目前我正在使用这个代码,但有了这个代码;2021";。你能帮我吗?
提前感谢!Felix
txt = "The apartment is rented out to a student since 2021. The monthly rent is 850 Euro. Additional costs are utilities (150 Euro)."
txt = ("".join(txt)).strip()
m = re.search(r'(?:((?i:rent)|JNKM)[w€:().!?-\, ]{0,40}(d+[,.]?d*)|(?:(d+[,.]?d*)[w€:().!?-\, ]{0,40}((?i:rent)|JNKM)))',"".join(txt))
txtrent = m.group().replace(".","").replace(",",".")
txtrent = re.findall(r"-?d+[,.]?d*", txtrent )
zustand = txtrent
print(zustand)```
检查一下:
txt = "The apartment is rented out to a student since 2021. The monthly rent is 850 Euro. Additional costs are utilities (150 Euro)."
txt = txt.replace('.', '')
pattern = 's'
result = re.split(pattern, txt)
txt = result[result.index('rent'): result.index('Euro')+1]
for i in txt:
if i.isdigit():
print(i)