?
Solved

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

Posted on 2014-01-22
11
Medium Priority
?
216 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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,…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
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

777 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