I'm quite new to regular expressions in Python. I have the following string and want to split them into five categories. I just use the split(), but it will just split according to white spaces.
s = "1 0 A10B 1/00 Description: This is description with spaces"
sp = s.split()
>>> sp
["1", "0", "A10B", "1/00", "Description:", "This", "is", "description", "with", "spaces"]
How can I write a regular expression to make it split like the following?
["1", "0", "A10B", "1/00", "Description: This is description with spaces"]
You may simply specify a number of splits:
s.split(' ', 4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With