编辑代码


import re
with open(r'C:\Users\32661\Desktop\test\测试.txt', 'r', encoding='utf-8') as file:
    text = ''
    for line in file:
        if '13465871080' in line:
            text += line

print(text)




# 假设您已经从文本中读取到了包含信息的字符串,并将其赋值给 text 变量


# 使用正则表达式找到第一个连续的数字串作为电话号码
match = re.search(r'\d+', text)
if match:
    # 利用字符串内置函数 index() 找到电话号码在原始字符串中的位置
    phone = match.group(0)
    index = text.index(phone) + len(phone)
    # 提取号码后面的所有文本并去除首尾的空格
    suffix_text = text[index:].strip()
    print(suffix_text)
else:
    print('未找到电话号码')