可以使用正则表达式进行匹配,例如:

import re

text = '绑定192928384'
pattern = r'绑定(\d{9})'

match = re.search(pattern, text)
if match:
    number = match.group(1)
    print(number)
else:
    print('No match')

输出:

192928384

解释:

  • r'绑定(\d{9})':正则表达式,表示匹配以'绑定'开头,后面跟着9位数字的字符串,并将这9位数字作为一个捕获组。
  • re.search(pattern, text):使用正则表达式 patterntext 中查找匹配项。
  • match.group(1):获取第一个捕获组的内容,即9位数字。

原文地址: https://www.cveoy.top/t/topic/oHcl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录