I created a regular expression:
((\(\s*) #match start parens
|(\d+\.?\d*) #match a number
|([+-/%^!]) #match operators
|([*]) #match the asterisk operator
|(\s*\)))+ #match the end parens
that is supposed to separate parentheses, numbers (integers and decimal (3
and 6.28
)), and operators (+-/*^%!
). I have tried a few tests
( (2 3 +) 6.28 +)
(3.14 6.28 +)
( (3 4 +) (5 6 +) *)
and I have noticed a few things. When I run the regular expression on expressions with two start parens, it seems to ignore one of the parentheses, and testing on the site seems to yield many instances of null and repetition of characters. Is there a way to match a valid expression and assign that to it's own group? For example, if I have the expression ( (2 3 +) 6.28 +)
, the groups generated would be: [(
, (
, 2
, 3
, +
, 6.28
, +
, )
]?
I remember one user posted an answer here that used a python regular expression, and it worked like a charm. The expression used something like (?.) or (.?) and the rest of my expressions. Unfortunately, I neglected to copy it down and the answer has been deleted. After that I have tried tweaking it quite a bit but nothing has worked. Any extra help is appreciated.