Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to match () pairs

Reply
Thread Tools

How to match () pairs

 
 
Peng Yu
Guest
Posts: n/a
 
      07-26-2008
Hi,

I would like to match a pattern such as

something( something_1( something_2( ...
(something_n)...)something_else_2)something_else_1 )

, where all the brackets pair up and there could be any number of
pairs. something_1, something_2, ..., and something_n could contain
'()' pair as well.

I'm wondering if there is any way to do this with regex?

Thanks,
Peng
 
Reply With Quote
 
 
 
 
Tad J McClellan
Guest
Posts: n/a
 
      07-26-2008
Peng Yu <(E-Mail Removed)> wrote:


> I would like to match



Then you should type:

perldoc -q match

How do I find matching/nesting anything?


> a pattern such as
>
> something( something_1( something_2( ...
> (something_n)...)something_else_2)something_else_1 )
>
> , where all the brackets pair up and there could be any number of
> pairs. something_1, something_2, ..., and something_n could contain
> '()' pair as well.
>
> I'm wondering if there is any way to do this with regex?



"This isn't something that can be done in one regular expression, no
matter how complicated."


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      07-26-2008
>>>>> "TJM" == Tad J McClellan <(E-Mail Removed)> writes:

TJM> Peng Yu <(E-Mail Removed)> wrote:

>> I would like to match


TJM> Then you should type:

TJM> perldoc -q match

TJM> How do I find matching/nesting anything?

>> a pattern such as
>> something( something_1( something_2( ...
>> (something_n)...)something_else_2)something_else_1 )
>>
>> , where all the brackets pair up and there could be any number of
>> pairs. something_1, something_2, ..., and something_n could contain
>> '()' pair as well.


TJM> "This isn't something that can be done in one regular expression, no
TJM> matter how complicated."

that could be done with (??{ code }) which is considered experimental
but 5.10 has (?PARNO) which says it can match nested parens. see perldoc
perlre and look for PARNO. it is still not for newbies and the faint of
heart but it is supported. it is still better/simpler to use a module like
text::balanced to match nested parens.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
re.sub(): replace longest match instead of leftmost match? John Gordon Python 13 12-20-2011 02:58 AM
pat-match.lisp or extend-match.lisp in Python? ekzept Python 0 08-10-2007 06:08 PM
$match = true() for empty $match?? Victor XML 2 05-17-2004 10:43 AM
Java regex can't match lengthy match? hiwa Java 0 01-29-2004 10:09 AM



Advertisments