I have several strings of the form "[one or more words] [number] [one or more words]" and I want to split them into the two strings and the number. For example, if the string is:
"A sample string 20 something"
I want to obtain:
str1 = "A sample string"
numb = 20
str2 = 'something'
I have (almost) achieved my goal with the following code:
for s in row.split():
if s.isdigit():
quants = s
temp = row.split("{}".format(quants))
str1 = temp[0].strip()
str2 = temp[1].strip()
this works fine for most cases. However, there are 2 exceptions which I'm not able to handle:
If the number is inside brackets, I want it to be counted as a string. For example:
"Some text (just as 1 example) 2 more words"
I want to have str1 = "Some text (just as 1 example)"
Sometimes the number is expressed in special character (Unicode?), ¼, ½ and ¾. How do I account for these?
I suspect the answer is to use regular expressions rather than a delimiter, but I could not really grasp how to use them yet.