在 python 中使用正则表达式 (re.findall) 从文本中提取 15 位数字字符串

Extract 15 digit string from text using regex (re.findall) in python

我的输入是--

Text = "My name is Alex , house no - 254456845 with mobile no. +91-11-22558845 and my account no. is - AB12569BF214558."

现在我想在我的输入文本上使用正则表达式 (re.findall) 并获得预期的输出。

预期输出=(它同时包含数字和字母,长度始终为 15)

[ "AB12569BF214558" ]

请帮忙

import re
results = re.findall('\b[A-Z0-9]{15}\b','''My name is Alex , house no - 254456845 with mobile no. +91-11-22558845 and my account no. is - AB12569BF214558.''')

您应该使用以下正则表达式模式:

\b[A-Z0-9]{15}\b

这将确保您匹配长度为正好 15 个字符的uppercase/numbers 字符串。示例脚本:

Text = "My name is Alex , house no - 254456845 with mobile no. +91-11-22558845 and my account no. is - AB12569BF214558."
matches = re.findall(r'\b[A-Z0-9]{15}\b', Text)
print(matches)

这会打印:

['AB12569BF214558']