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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find 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
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Unreadable
Name: Mick
Date: 4/1/2014 4:06:49 PM
Comment:
If you are going to use end-of-line comments you should indicate where those comments end. As it is, lots of trouble to try to break this into lines that can actually be parsed.


Title: Master
Name: Tim
Date: 6/19/2012 10:46:42 AM
Comment:
I dont know if u want ppl to decipher the expression outta that... or am i just missing something


Title: Master
Name: Tim
Date: 6/19/2012 10:44:49 AM
Comment:
I dont know if u want ppl to decipher the expression outta that... or am i just missing something


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