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
In reply to Re: replace text with function ?
by ww
in thread replace text with function ?
by 2xlp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |