In the string
x='(var1 * 1.3e4 + abc)/log(blabla+2E3)'
I would like to substitute var1
, abc
, and blabla
with '1'
, say to pass into ast
and see if this is a proper expression. I don't want to touch log
or e
or E
. Of course there are other things I may want to skip, like sin
.
Currently I'm using something like
for match in re.findall(r'[a-zA-Z]+',x):
if match.startswith('log') or match.lower()=='e': continue
x = x.replace(string,'1')
The log can come in a few flavors, hence startswith
- obviously won't work for any case. I would prefer to use re.sub
in one go.