Issue
I need to break down a string into 3 chunks, (Example: ABC123DEF would end up as X=ABC Y=123 Z=DEF) and need some assistance in getting the alphabetical parts to not be combined into X=ABCDEF as apposed to separate items.
Solution
re.split
by \d+
and use grouping to keep the splitting-text.
>>> import re
>>> s = 'ABC123DEF'
>>> re.split('(\d+)', s)
['ABC', '123', 'DEF']
Answered By - timgeb
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.