I'm trying to use regex to replace instances of a fraction (specifically 1/2) with the decimal equivalent
string = "7 1/2"
re.sub(r'[1/2]', '.5', string)
Firstly, I think the above replaces all instances of 1, /, 2 with .5, whereas I'm trying to find and replace the entire term "1/2"
Secondly, how do you handle the leading space before the fraction itself?
[ ]use()to capture the fraction group