Displaying page
of
pages;
Items to
Title |
Test
Details
Mathematical Expression
|
Expression |
^ (?: (?> # non backtracking for alternated tokens (?: \- # "-" operator (?=\d|\() # followed by digit or "(" ) | (?: (?<=\d|\)) # preceded by digit or ")" (?:\+|\/|\*) # basic operators except "-" (?=\d|\(|\-) # followed by digit or "(" or "-" ) | (?<parenthesis> # incremente balancing group "parenthesis" counter (?<=^|\+|\/|\-|\*|\() # preceded by start of line or basic operator or "(" \( # opening parenthesis "(" (?=\d|\(|\-) # followed by digit or "-" or "(" ) | (?<-parenthesis> # decrement balancing group "parenthesis" counter (?<=\d|\)) # preceded by digit or ")" \) # opening parenthesis ")" (?!\d) # not followed by digit ) | (?: (?<=\(|\-|\+|\*|\/|^) # preceded by start of line or basic operator or "(" (?:\d+(?:\,\d{1,4})?) # number with optional 4 decimal with comma as decimal marker (?=$|\)|\-|\+|\*|\/) # followed by end of line or ")" or basic operator ) ) + (?(parenthesis)(?!)) # test for balancing group "parenthesis" counter ) # unnamed group whole expression $
|
Description |
Useful for validating a basic singleline mathematical expression prior to calculating its value (as with eval).
It allows numbers with optional 4 decimals marked with comma.
Valid operations: addition, substraction, multiplication, division.
Accepts negative numbers.
Accepts only round brackets and balances them (.NET ONLY !!!).
|
Matches |
-10/-3,5 | ((5,4-234556.1)*(0,899/2)-4,6778) | (1)+(-2)+-3*-5
|
Non-Matches |
10*4,55555 | (-10+3)+ | -10*95,5+(-3
|
Author |
Rating:
Bruce Wayne
|
Displaying page
of
pages;
Items to