社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

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