I've been struggling with this for quite awhile (not being a regex ninja), searching stackoverflow and through trial an error. I think I'm close, but there are still a few hiccups that I need help sorting out.
The requirements are such that a given equation, that includes variables, exponents, etc, are split by the regex pattern after variables, constants, values, etc. What I have so far
Regex re = new Regex(@"(\,|\(|\)|(-?\d*\.?\d+e[+-]?\d+)|\+|\-|\*|\^)");
var tokens = re.Split(equation)
So an equation such as
2.75423E-19* (var1-5)^(1.17)* (var2)^(1.86)* (var3)^(3.56)
should parse to
[2.75423E-19 ,*, (, var1,-,5, ), ^,(,1.17,),*....,3.56,)]
However the exponent portion is getting split as well which I think is due to the regex portion: |+|-.
Other renditions I've tried are:
Regex re1 = new Regex(@"([\,\+\-\*\(\)\^\/\ ])"); and
Regex re = new Regex(@"(-?\d*\.?\d+e[+-]?\d+)|([\,\+\-\*\(\)\^\/\ ])");
which both have there flaws. Any help would be appreciated.