我正在尝试按数字将字符串与其他所有内容分开。
string = 'hello_there16.txt'
match = re.match(r"([a-z]+)([0-9]+)",string , re.I)
match.groups()
预期输出:
(hello_there,16,.txt)
但是match
的输出为空。
答案 0 :(得分:0)
如果要拆分,则可以使用re.split
:
import re
string = 'hello_there16.txt'
result = re.split("([0-9]+)", string)
print(result)
输出:
['hello_there', '16', '.txt']