Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-29-2012, 01:40 PM
|
#1
|
|
LQ Newbie
Registered: Feb 2009
Posts: 8
Rep:
|
Perl REGX match between parentheses
I have a script that reads a file that looks as such.
First(James) Zip(1234)
Last(Jones)
I have function that you pass a item to find (such as "First"). A simple regex parses the file and returns the data. /$data\((w+)\)/
This works find, but now there are some items that aren't words, some have spaces and commas in them. How can I return the data between the parentheses regardless of what text is between them?
|
|
|
|
11-29-2012, 02:33 PM
|
#2
|
|
Senior Member
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,856
|
Last edited by markush; 11-30-2012 at 12:41 AM.
Reason: typo
|
|
|
|
11-29-2012, 06:40 PM
|
#3
|
|
Senior Member
Registered: May 2005
Posts: 4,396
|
Quote:
Originally Posted by Boomn4x4
I have a script that reads a file that looks as such.
First(James) Zip(1234)
Last(Jones)
I have function that you pass a item to find (such as "First"). A simple regex parses the file and returns the data. /$data\((w+)\)/
This works find, but now there are some items that aren't words, some have spaces and commas in them. How can I return the data between the parentheses regardless of what text is between them?
|
The regular expression can be:
- '$1' will contain the data you need to be extracted between parenthesis.
|
|
|
|
11-29-2012, 07:43 PM
|
#4
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,265
|
Quote:
Originally Posted by markush
|
Shouldn't that be:
??
I use the same pattern myself for parsing text with opposing tokens like parentheses, curly braces, and brackets.
--- rod.
|
|
|
|
11-29-2012, 08:32 PM
|
#5
|
|
Senior Member
Registered: May 2005
Posts: 4,396
|
Quote:
Originally Posted by theNbomr
...
I use the same pattern myself for parsing text with opposing tokens like parentheses, curly braces, and brackets.
--- rod.
|
If we are generalizing, then why not http://perldoc.perl.org/Text/Balanced.html ?
|
|
|
|
11-30-2012, 12:42 AM
|
#6
|
|
Senior Member
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,856
|
Quote:
Originally Posted by theNbomr
|
Thanks theNbomr, I've changed it.
Markus
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:26 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|