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
Post a Comment