Perl matching nested parentheses problem

Source: Internet
Author: User

text: (1+2(123+ (888)3) DDF) wwww (SDF (SDFDSF) GGGG) Match :1+21238883 ddf SDF SDFDSF gggg

Match code:

#!/usr/bin/perl UseStrict; Usewarnings; UseRe'Eval';my $str='(1+2 (123+ (888) 3) DDF) wwww (SDF (SDFDSF) GGGG)';my @arr;my $re= qr/(? {Local $a=0}) (?> (?:( [^()]+)(? {Push @arr,$1})|#push the matched content to the @arr# curing group to reduce the return. \((? {$a++})|#Encounter opening parenthesis $a+1\)(? (? {$a!=0})(? {$a--})|#if $ A does not equal 0 then it encounters a closing parenthesis $a-1(?!))) *)(? (? {$a!=0})(?!)) /x;#otherwise continue to match if you continue to encounter $ A not equal to 0 to continue matching to end of line1  while($str=~ /\($re\)/g);Print Join("\ n",@arr);

Perl matching nested parentheses problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.