Reputation: 624
I have a string like this
mystr = "K1_L1_L2 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?
Upvotes: 0
Views: 82
Reputation: 5604
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']
Upvotes: 4