RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Expressions by User

   Displaying page 1 of 1 pages; Items 1 to 1
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: The rating for this expression. Bruce Wayne
   Displaying page 1 of 1 pages; Items 1 to 1

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials