【发布时间】:2021-02-24 14:20:54
【问题描述】:
我正在尝试从文本中提取电话号码。但我不希望重新格式化电话、提取数字部分或其他任何东西,但我只想从文本中提取未更改的、不重新格式化的原始电话号码字符串。 我用 PhoneNumberMatcher() 方法尝试了“phonenumbers”库(https://github.com/daviddrysdale/python-phonenumbers)。它工作得很好,就获取格式化的电话号码而言,这是我不需要的,我只需要电话号码的原始子字符串。有办法吗?
for match in phonenumbers.PhoneNumberMatcher(text, "US"):
unformatted_phone = match.number
#formatted_phone = str(match.number)
#formatted_phone = phonenumbers.format_number(match.number, None)
formatted_phone = phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.INTERNATIONAL)
【问题讨论】:
标签: python regex phone-number data-extraction