python中的re.split()

import re
m = re.split( '\d+' , 'abc23def44')  
print(m)

['abc', 'def', '']

import re
m = re.split( '(\d+)' , 'abc23def44')  #加括号
print(m)

['abc', '23', 'def', '44', '']


import re
m = re.split( '\d+' , 'acb123def456ghi')  
print(m)

['acb', 'def', 'ghi']

import re
m = re.split( '(\d+)' , 'acb123def456ghi')  
print(m)

['acb', '123', 'def', '456', 'ghi']

不加括号,就不显示匹配的项,即\d+,加括号,显示匹配的项


你可能感兴趣的:(python)