Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Substitute strings

by clueless newbie (Curate)
on Sep 12, 2016 at 12:20 UTC ( [id://1171578]=note: print w/replies, xml ) Need Help??


in reply to Substitute strings

I assume that you're interested in func1 followed by balanced parenthesis so this might be of use.
#!/usr/bin/env perl use strict; use warnings; my $balpar_re=qr/ ( \( # opening ( (?:[^'"()]++ # Not a ', ", ( or ) - no b +acktracking |(?:'(?:[^']|\')*?') #' a single quote string |(?:"(?:[^"]|\")*?") #" a double quote string |(?-1) # must be a ( or ) so recur +se )*+ # zero or more time - no ba +cktracking \) # closing ) ) /x; my $text=<<'__EOT__'; xfunc1("shouldn't be changed!") func1 (abc,"abc","should,be,changed!"); func1(arg(),narg()); __EOT__ if ($text=~ s{\bfunc1\s*$balpar_re}{newtext}g) { print $text; }; __DATA__

Replies are listed 'Best First'.
Re^2: Substitute strings
by AnomalousMonk (Archbishop) on Sep 12, 2016 at 18:00 UTC
        |(?-1)                         # must be a ( or ) so recurse

    kepler: Please note that the  (?-PARNO) regex operator is only available with Perl version 5.10 and above. Please see Extended Patterns in perlre.


    Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1171578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-24 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found