Skip to content

Instantly share code, notes, and snippets.

@MagicHen25
Created February 13, 2017 14:33
Show Gist options
  • Save MagicHen25/1210fadecf34adff1bdb6b78a3231743 to your computer and use it in GitHub Desktop.
Save MagicHen25/1210fadecf34adff1bdb6b78a3231743 to your computer and use it in GitHub Desktop.
'''
1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) )
'''
import re
calcStr = "1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) )"
calcStr = re.sub("\ ","",calcStr)
# print(calcStr)
tmpStr = ""
# tmpStr = re.search("\([\(\)\+\-\*/\d]+",calcStr)
# print(tmpStr.group())
def strExecute(inStr):
print(inStr)
outStr = ""
outStr = re.search("\([\(\)\+\-\*/\d]+",inStr)
if outStr is not None:
outStr = strExecute(outStr.group(0)[1:])
print("pos1",outStr)
return outStr
else:
return inStr
tmpStr = strExecute(calcStr)
print("[Final]:",tmpStr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment