私信  •  关注

anotherGatsby

anotherGatsby 最近创建的主题
anotherGatsby 最近回复了
3 年前
回复了 anotherGatsby 创建的主题 » 我的Python正则表达式在代码中工作不正常

你可以简化你的表达 r"(?<=Legal Description:\n)(.*)(?=\nProperty Use:)"

import re

str = """General Info
Status: Certified
ACCOUNT
Property ID:
408123
Geographic ID:
Type:
P
Agent:
LETS GO TAX SERVICES - PO BOX 111
(Authorized)
Legal Description:
AREA THAT I WANT TO CAPTURE
Property Use:
OWNER
Name:
ABCD GAME SERVICE LLC
Secondary Name:
ATTN ACCTS PAYABLE
Mailing Address:
PO BOX 2222 NEW YORK NY 222515-12354
Owner ID:
123456"""

rgx  = r"(?<=Legal Description:\n)(.*)(?=\nProperty Use:)"

lst = re.findall(rgx, str)

print(lst[0])
# 'AREA THAT I WANT TO CAPTURE'

Try python Try regex