Solved

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

Posted on 2014-01-22
11
215 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 500 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
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!

 

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

Industry Leaders: 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

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
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…

717 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