Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Conditional regex

by linuxer (Deacon)
on May 08, 2009 at 21:13 UTC ( #762950=note: print w/ replies, xml ) Need Help??


in reply to Conditional regex

Although nowadays I'd prefer to use HTML::Parser or something similar, I think you could use a subroutine call in the replacement part (and use the /e modifier).

sub foo { my $bar = shift; if ( $CONDITION ) { #modify $bar if you need to } return $bar; } my $text =~ s{(<img.+?>)}{foo($1)}sige;

update1: changed quantifier to +?


Comment on Re: Conditional regex
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2015-07-07 01:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls