?
Solved

Simple Regular Expression Question

Posted on 2008-01-30
5
Medium Priority
?
176 Views
Last Modified: 2010-04-15
What is the pattern for matching any text occuring within a parenthesis?

I thought that

@"\(\w*\)"

would do the trick but RegularExpressions seem to be forever my Achilles Heel :)

Thanks for your help.
0
Comment
Question by:tradeline
  • 3
  • 2
5 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 20783090
\(\w*\)
is any string of word characters in parenthesis
\(.*\)
or
\(.*?\)
is any string of non \n characters in parenthesis
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 2000 total points
ID: 20783100
tradeline,

If you would not have parentheses inside them then I would use ...

\([^)]*\)

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20783224
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0
 
LVL 85

Expert Comment

by:ozo
ID: 20784542
Assuming no \n characters, that matches the same thing as
\(.*?\)
To allow ) inside of () you could use
\(.*\)
To disallow either ( or ) inside () you could use
\([^()]*\)
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20784631
Great summary Ozo.  I was surprised there wasn't a split but secretly "pleased" to win one. ;)

bol
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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,…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
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

601 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