Python 正则表达式提取八位数字 - 代码示例
使用 Python 正则表达式提取八位数字
要使用 Python 中的正则表达式提取八位数字的数据,可以使用 re 模块。
以下是提取八位数字的正则表达式示例代码:
import re
pattern = r'\b\d{8}\b'
text = '这是一段文本,包含 12345678 和 23456789 两组数字。'
result = re.findall(pattern, text)
print(result)
代码中,使用 \b 匹配单词边界,\d 匹配数字,{8} 匹配 8 个数字。
运行结果为:
['12345678', '23456789']
这样就可以提取文本中的所有八位数字了。
原文地址: http://www.cveoy.top/t/topic/lkmy 著作权归作者所有。请勿转载和采集!