in reply to replace text with function ?

Note, however, that -- as originally posted --your regex does NOT match (has a typo?).

#!/usr/bin/perl -lw use strict; # [id://735593] my $string = '<img id="image-1" src="http://site.com/a.gif" />'; my $regex = qr|<img id="image-(\d)" src="http://site.com/(\w\.\w+)" /> +|; # works # ^^^^^^^ + < modified here if ( $string =~ /$regex/ ) { print "\$regex matches: $1 and $2"; } else { print "No match in $regex"; } my $OPregex= qr|<img id="image-(\d*) src="http://site.com/(\w*)" />|; + # OP's with (added) terminating "|;" if ( $string =~ /$OPregex/ ) { print "\$OPRegex matches: $1 and $2"; } else { print "no match in \$OPRegex"; }

Output:

perl F:\_wo\pl_test\735593.pl $regex matches: 1 and a.gif no match in $OPRegex

Replies are listed 'Best First'.
Re^2: replace text with function ?
by 2xlp (Sexton) on Jan 15, 2009 at 20:16 UTC
    ha ha, yes! nice catch!

    that wasn't the real regex -- stuff is working PERFECTLY now.

    thanks to all!