我使用的是Python版本的Google的libphonenumbers,但是当我在不同的文本上尝试这个库时,有时Python函数不会返回任何东西,而很明显那里有一个电话号码,有时它们确实返回电话号码。请看下面:
print(x2)
for match in pnum.PhoneNumberMatcher(x2, "US"):
print(match) #for the text above, it did not get the number
输出:
I just read your profile and thought it was really great. I also thought you were cute and loved the fact that you go hiking with your brothers every summer. If you want to know anything more about me, just ask. My num 555-121-5468.
有了上面的这段文字,它不会返回我任何电话号码。 但在其他情况下,如以下情况,此函数会为我提供正确的输入:
x9 = "hay I hate to cut you short, its been fun chatting, but unfortuantely I gotta run. I am gald we became friends though. my number is (323) 2387890"
for match in pnum.PhoneNumberMatcher(x9, "US"):
print(match)
输出:
PhoneNumberMatch [132,145) (323) 2387890
我不知道是什么问题导致了这个问题,我是Python和这个库的新手,非常感谢您的理解。你知道吗
555-121-5468看起来像是一个有效的美国电话号码,但实际上不是
PhoneNumberMatcher
类constructor接受leniency
参数,该参数定义类与候选电话号码(code)匹配的严格程度。此参数的可能值leniency
的默认值是1
,它将只匹配有效的电话号码。将此更改为0
将匹配可能的电话号码,如555-121-5468。你知道吗555前缀不是真正的前缀,但在美国电视和电影中用于虚构的电话号码。从Wikipedia:
相关问题 更多 >
编程相关推荐