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
> 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/"
TJM> Peng Yu <Peng...@gmail.com> 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 ------ u...@stemsystems.com -------- 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 ---------