Nice example program below, but it does have a bug in it.  Here is the
fix.


    $str1 =~ s/<IMG[^>]*>/<IMG = IMAGE REMOVED>/gi;




-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jeff D
Sent: Tuesday, May 16, 2006 10:04 AM
To: Craig Cardimon; [email protected]
Subject: Re: Need help with IMG tag containing unbalanced parentheses



--- Craig Cardimon <[EMAIL PROTECTED]> wrote:

> I need find the IMG tag in the line below, substituting for it the 
> phrase, "IMAGE REMOVED"
> 
> ***
> 
> <P align=center><IMG SRC="c40736033.gif"
> ALT="LARGE-CAP VALUE INDEX FUND
> LOGO)"></P>
> 
> ***
> 
> Notice the unbalanced parentheses. There is no opening parenthesis to 
> match the closing one.
> 
> I have used the following pattern matching expressions in this 
> attempt:
> 
> /(<img\s+([^>]*)>)/gi
> /(<img([^>]*)>)/gi
> /(<img(.*?)>)/gi
> 
> I get the same error message every time:
> 
> Uncaught exception from user code:
>       Unmatched ) in regex; marked by <-- HERE in m/<IMG 
> SRC="c40736033.gif"
> ALT="LARGE-CAP VALUE INDEX FUND LOGO) <-- HERE ">/
> 
> Any hints, tips, or suggestions would be appreciated.
> 
> --
> 
> Craig [ "Missed it by THATMUCH" ]
> 
> 

Using the example input you've given, I believe this does what you're
looking for and I didn't receive the error you indicate.  Hope this
helps.

JD

#! /usr/local/bin/perl -w
use strict;

my $str1 = "<P align=center><IMG SRC=\"c40736033.gif\"
ALT=\"LARGE-CAP VALUE INDEX FUND LOGO)\"></P>"; my $str2 = $str1;

if ($str1 =~ m/<IMG(.*)>./i)
    {
    print "MATCHED\n[$1]\n";
    #
    # To substitute everything from the SRC onwards to the first <
    #
    $str1 =~ s/<IMG(.*)>(.)/<IMG = IMAGE REMOVED> $2/gi;
    print "str1 [$str1]\n";
    #
    # or if wanting to remove the entire reference to the IMG
    #
    $str2 =~ s/<IMG(.*)>(.)/IMAGE REMOVED $2/gi;
    print "str2 [$str2]\n";
    }
else
   { print "NO MATCH\n"; }


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com _______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to