[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Regex   sum  (  itemOne  *   itemTwo +  itemTwoX -  itemThree ..... )

Posted on 2005-04-26
Medium Priority
Last Modified: 2006-11-18
I need to extract these items : itemOne,itemTwo, etc. Basically, every word between the parenthesis. There may be spaces before/after ( ) and the seperators might be [+/*-] .

I have tried this, but the parenthesis seem to be messing up the expression (combined with my newbieness on regex I'm sure) .

FYI: This is going into a web page. The itemOne,itemTwo,etc are elements that I need to put onchange events into so that if any element in the expression changes, the calculation is done automatically. I wouldn't know the fields during the design of the page.

Thanks Experts !
Question by:lrr81765
  • 2
LVL 32

Accepted Solution

Batalf earned 2000 total points
ID: 13866529

<script type="text/javascript">
var string = "sum  (  itemOne  *   itemTwo +  itemTwoX -  itemThree )";
var items = string.split(/[\*\+\-\/]/g);

for(var no=0;no<items.length;no++){
    items[no] = items[no].replace(/.*?\((.*?)/,'$1').replace(/\)/g,'');
    items[no] = items[no].replace(/\s*?([^\s]+)\s*/,'$1');


Author Comment

ID: 13866642
Any chance you might have a .net RegEx example of this same thing? That is where the actual processing takes place (sorry for that).
LVL 32

Expert Comment

ID: 13866739
Sorry, my .net knowledge is extremely limited. If .net supports standard regexp, then it should work if you find .net's functions for split and replace.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question