我有这段代码,用来用Python语言解析街道和门牌号
import re
def parse_street(address):
pattern = r'^(.*?)(?i)\b no\b'
match = re.match(pattern, address)
if match:
return match.group(1).strip()
else:
return None
def parse_housenumber(address):
pattern = r'(?i)\bno\.?\s*([\dA-Z]+)'
match = re.search(pattern, address)
print(match)
if match:
return match.group(1)
else:
return None
df['street'] = df['address'].apply(lambda x: pd.Series(parse_street(x)))
df['house_number'] = df['address'].apply(lambda x: pd.Series(parse_housenumber(x)))
为什么我在PostgreSQL中使用相同的regex语法查询运行查询时出错:
SELECT (regexp_matches('Jl. ABC No.01', '^(.*?)(?i)\b no\b'))[1]
错误消息为:
ERROR: invalid regular expression: quantifier operand invalid
个
PYTHON中的regex与其他系统中的regex有什么不同?如何将我的python函数转换为PostgreSQL语法?我想在同一个表中的"Address"列中添加"Street"和"house_number"列