I am currently using the findall regex to find and parse my equation such as this:
re.findall(r'\s*([\^.+*/-]|\d+)', evaluate)
what I tried to do is find letters among what I already found:
re.findall(r'\s*([a-zA-Z\^.+*/-]|\d+)', evaluate)
re.findall(r'\s*([a-zA-Z]|[\^.+*/-]|\d+)', evaluate)
re.findall(r'\s*([\^.+*/-]|\d+\w+)', evaluate)
Each one of these either gives errors or cuts off my operations and also did not give me my letters to parse. Second, I wanted to parse the letters how I parsed the numbers where 123
is one number, such as abc
will be one section.
Currently: if I had 5*100+abc
it'll parse like this:
['5', '*', '100', '+']
Any suggestions?
I should note that abc123
IS NOT one number. so putting just \w+
isn't a solution.
I want all abc's and numbers separated:
['123', 'abc'] or ['abc', '123']
And they should be separate like this \^
, .
, +
, *
, /
, -
, 123
, abc
I am currently using the findall regex to find and parse my equation such as this:
re.findall(r'\s*([\^.+*/-]|\d+)', evaluate)
what I tried to do is find letters among what I already found:
re.findall(r'\s*([a-zA-Z\^.+*/-]|\d+)', evaluate)
re.findall(r'\s*([a-zA-Z]|[\^.+*/-]|\d+)', evaluate)
re.findall(r'\s*([\^.+*/-]|\d+\w+)', evaluate)
Each one of these either gives errors or cuts off my operations and also did not give me my letters to parse. Second, I wanted to parse the letters how I parsed the numbers where 123
is one number, such as abc
will be one section.
Currently: if I had 5*100+abc
it'll parse like this:
['5', '*', '100', '+']
Any suggestions?
I should note that abc123
IS NOT one number. so putting just \w+
isn't a solution.
I want all abc's and numbers separated:
['123', 'abc'] or ['abc', '123']
And they should be separate like this \^
, .
, +
, *
, /
, -
, 123
, abc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.