c# - Need a regular expression for detecting simple math expressions -


i'm going validate simple math expressions such these:

a = 1 + 2 b = 2.2 = b + 5.5 = b - -5.5 = -1 + 2 = -2.4 = 3.5 / 0.2 + 1 = 3 * -2.1 

note: operator precedence not important!

i try following expressions got nothing!!!

for digits: ^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$ operators: [-]|[+]|[*]|[/] variables: [a-z]+|[a-z]+ 

i put these expressions in c# string variables , used .net regex.matches(...) find matches. got nothing!

this not great job regular expressions. if want evaluate true mathematical expression not able come regex can handle cases. carl norum said similar discussion why can't parse html regex.


Comments

Popular posts from this blog

c++ - Compiling static TagLib 1.6.3 libraries for Windows -

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea -

asp.net - call stack missing info on mono with apache and mod_mono -