Python regex and splitting
I have a string like this
mystr = "K1_L1_L开发者_如何学运维2 XX"
I want to break it to the following format
K1 L1 L2 XX
where K1, L1, L2 can be anything but have this format of a char followed by a number. I am doing this in python using the following regex:
a = "K1_L1_L2 XX"
re.split("[\c\d\_]+",a)
which gives me the following output
['K', 'L', 'L', ' ', '.', '']
but I want something like this
['K1', 'L1', 'L2', ' ', '.', '']
what is the possible workaround?
There are problems with the code you have included in your example above. I would edit them but I'm not 100% sure what you are looking for.
The following:
import re
a = "K1_L1_L2 XX"
print re.split("[ _]", a)
will print:
['K1', 'L1', 'L2', '', 'XX']
maybe
re.split("([A-Za-z]\d)",a)
?
精彩评论