the output of re.split in python doesn't make sense to me -
print (re.split(r'[a-fa-f]','finqwenlaskdjriewasfsdfddsafsafasa',re.i|re.m)) print (re.split(r'[a-fa-z]','finqwenlaskdjriewasfsdfddsafsafasa',re.i|re.m)) print (re.split(r'\d*','sdfsfdsfds123212fdsf2')) print (re.split(r'\d','sdfsfdsfds123212fdsf2')) print (re.split(r'\w+','dsfsf sdfdsf sdfsdf sfsfd')) ['', 'inqw', 'nl', 'sk', 'jri', 'w', 's', 's', '', '', 'dsafsafasa'] ['', 'inqw', 'nl', 'sk', 'jri', 'w', 's', '', '', '', 'ddsafsafasa'] ['sdfsfdsfds', 'fdsf', ''] ['sdfsfdsfds', '', '', '', '', '', 'fdsf', ''] ['', ' ', ' ', ' ', '']
i think output here weird. pattern split string turned '' in output list sometimes, disappear other time.
the pattern split string turned
''
in output list sometimes, disappear other time.
no, pattern (or matched) never included in outputs there. ''
what's between matches. because that's re.split
does. example:
>>> re.split(r'\d','sdfsfdsfds123212fdsf2') ['sdfsfdsfds', '', '', '', '', '', 'fdsf', '']
you're splitting digits, , substring '123212'
has 6 digits, there 5 empty strings between them. that's why there 5 empty strings in output there.
Comments
Post a Comment