Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

script for checking numeric arithmetic expressions

Last post 11-07-2008, 8:28 AM by prometheuzz. 1 replies.
Sort Posts: Previous Next
  •  11-07-2008, 8:19 AM 48072

    script for checking numeric arithmetic expressions

    Hi All 

    I am looking for a script which will check valid numberic arithmetic expressions

    e.g 3+4-6*7 is valid

         3+6-8*8/7+9 is valid

        x+ 4-5 ISN'T valid

       n++ ISN'T valid

     

    Can anyone PLEASE help me as I am newbie to Regex.

     Thanks

    Akshay

  •  11-07-2008, 8:28 AM 48073 in reply to 48072

    Re: script for checking numeric arithmetic expressions

    Given those examples, the this regex will match both of your valid expressions and will not match the latter two:

    ^\d([-+*/]\d)+$

    But I suspect you have quite som hidden requirements up your sleave that you didn't mention in your original post. So, before posting one or two more examples that should be matched by the regex (whcih don't get matched by my suggestion), I urge you to explain your problem in some more detail and also post quite a few valid- and invalid expressions which handle all your corner cases.

    Good luck.

View as RSS news feed in XML