Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 19th, 2013, 07:58 AM
Noisebreath Noisebreath is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 1 Noisebreath User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 sec
Reputation Power: 0
Find parenthesis construct

Hi,

i need a regexp that matches a string within a text from the first opening parenthesis after an equal sign "=(" to its closing parenthesis no matter how many opening and closing parenthesis are between them.
For example :

"The first parenthesis will ( be ignore . an example text containing =(hei() whats(up) with (()yoou) ( what are your plans today)? ) . the next parenthesis will be ignored ) text"

It has to find the following text snippet : =(hei() whats(up) with (()yoou) ( what are your plans today)? )

i cant get this done. Anyone an idea how to solve this? :-/

thx

Reply With Quote
  #2  
Old February 19th, 2013, 08:15 AM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,847 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 10 h 15 m 31 sec
Reputation Power: 813
Hi,

you cannot do this with a regular expression -- unless you have Perl and can make use of the pseudo-regexes also supporting features like recursion.

Regular grammars are the weakest grammars of all. They can only describe a simple sequence of characters, nothing more -- although many people seem to view them as an all-powerful parsing tool.

I guess the best workaround in this case would be to search for "=(" and then simply use a counter to find the closing parenthesis: start the counter at -1, increment it for every ")" and decrement it for every "(". When the counter is 0, you've found the closing parenthesis.

Reply With Quote
  #3  
Old April 1st, 2013, 07:49 AM
klipangel klipangel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 9 klipangel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 34 m 23 sec
Reputation Power: 0
not sure what you r trying to ask, but if you want all the text between =("text also containing inner paranthesis." ) then you cawrite regular expression as follows:- =\((.*?)\). you can use backslash to tell interpreter that subsequent character followed in the text should be considered as it is and the the second paranthesis which doesnot have backward slash is you regex to obtain text in the outer paranthesis. and if you want to ignore all the parenthesis then regex is:- =\(([a-z 0-9 A-Z other possible characters excluding parenthesis]+)\)

Last edited by klipangel : April 1st, 2013 at 07:55 AM. Reason: wanted to make answer more precise

Reply With Quote
  #4  
Old April 1st, 2013, 12:11 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,682 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 35 m 32 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Quote:
Originally Posted by klipangel
not sure what you r trying to ask, but if you want all the text between =("text also containing inner paranthesis." ) then you cawrite regular expression as follows:- =\((.*?)\). you can use backslash to tell interpreter that subsequent character followed in the text should be considered as it is and the the second paranthesis which doesnot have backward slash is you regex to obtain text in the outer paranthesis. and if you want to ignore all the parenthesis then regex is:- =\(([a-z 0-9 A-Z other possible characters excluding parenthesis]+)\)

The parentheses have to be balanced. What you proposed doesn't support that and would only find "=(hei()" in the example given.

Also, PHP, Perl, and .NET can do this with purely regular expressions.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Find parenthesis construct

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate 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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap