要从文本中识别数字,可以使用regex(正则表达式)
import re text = "FB-19876 is your code" code = re.findall(r'\d+', text) print(code)
上面示例的输出将是
['19876']