Split on the token '$var'
, then replace the two parts from the left and right sides respectively with an empty string, and you will get the value of the token.
>>> str1 = 'WeDrank$varCupCoffeeToday'
>>> str2 = 'WeDrank2CupCoffeeToday'
>>> parts = str1.split('$var')
>>> str2.replace(parts[0],'').replace(parts[1],'')
'2'
>>> str1 = 'WeDrank2CupCoffee$var'
>>> str2 = 'WeDrank2CupCoffeeToday'
>>> parts = str1.split('$var')
>>> str2.replace(parts[0],'').replace(parts[1],'')
'Today'