[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Need pattern matching expressions within ()s that contain at least one "+".

Posted on 2014-01-22
11
Medium Priority
?
217 Views
Last Modified: 2014-01-22
This seems like it should be the simplest thing in the world.  I am looking for a pattern to match expressions within ()s that contain at least one "+".
0
Comment
Question by:NevSoFly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 14

Accepted Solution

by:
sentner earned 2000 total points
ID: 39800729
This should work, though does not account for nested parentheses.

[(][^)]*[+][^)]*[)]

Open in new window

0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39800733
Something like this? \([^)]*\+\)
0
 

Author Comment

by:NevSoFly
ID: 39800746
@Sentner

I tried your suggestion but it didn't find any matches.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:NevSoFly
ID: 39800759
@ Marco Gasi

I tried your suggestion too but still no matches.
0
 
LVL 14

Expert Comment

by:sentner
ID: 39800796
Are you using it inside of a script or such?  I tested with sed, and it worked fine:

> echo "this+ (is a test) (+match this) (But not this)"| sed -e 's/[(][^)]*[+][^)]*[)]/here/'
this+ (is a test) here (But not this)
0
 
LVL 84

Expert Comment

by:ozo
ID: 39800800
What was the string in which you were trying to find the matches?
0
 

Author Comment

by:NevSoFly
ID: 39800847
I am using it inside a VB.net function.
I am using http://www.regexr.com/ to test the patterns and my test string is "(2d)(4)(2a+2n)+(3xz)-(-4x)-(2a+2n)".
0
 
LVL 84

Expert Comment

by:ozo
ID: 39800881
Sentner's suggestion seemed to work for me when I tested it there on that string.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39800943
I posted my (wrong) solution without seeing Sentner's one: now I have tested it and I agree with ozo, it works fine in RegexBuddy.
0
 
LVL 14

Expert Comment

by:sentner
ID: 39800950
Can you share the syntax you're using in your function?

I tested with your string using command line and it worked:

> echo "(2d)(4)(2a+2n)+(3xz)-(-4x)-(2a+2n)" |  sed -e 's/[(][^)]*[+][^)]*[)]/here/g'
(2d)(4)here+(3xz)-(-4x)-here
0
 

Author Comment

by:NevSoFly
ID: 39801449
Sentner's suggestion did work after all.  When I copied and pasted it into regexr.com I didn't notice an empty space at the end.  Once I deleted it everything worked.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

650 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