c# - Matching unary signs and parsing math with Regex -


one last regex problem need with. trying able parse math expression, while still having regex recognize unary symbols. using following parse integer:

[\+\-]?[0-9]+ 

which works fine in these 2 scenarios:

myvar = -5 myvar = +5 

regex correctly identifies both -5 , +5 integers. problem if have scenario this:

myvar = 7-5 

this, however, gets matched correctly:

myvar = 7*-5 

now regex doing in 7-5 scenario identifying 2 integers, 7 , -5. in reality, want able identify integer (7), minus sign (-) , integer (5). regex pattern need this?

thanks in advance. .net regex, way.

regex isn't best choice parsing math expressions. @ recursive descent parser or reverse polish notation or other more appropriate algorithm.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -