[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] pattern replacing



On Thu, May 13, 1999 at 09:38:37PM -0400, Rick wrote:
> how do i replace a string that may have variables in it with another
> string that would have reg. expressions and/or variables??  this is what
> i am trying:
> 
> y/<a href="(.+)" target="_top"><img height="25" width="70"
> src="(.+)hist_p\.gif" align="absmiddle" border="0" alt="(.+)"><\/a>/<img
> height="25" width="70" src="$2hist_p\.gif" align="absmiddle" border="0"
> alt="$3">/d;

y/// and tr/// are for doing character-to-character translation.  The /d
option is for deleting any characters that don't have replacements
specified.
Why do I suspect that you're trying things randomly to find a solution?  :(



> and i also tried:
> 
> 				s/<a href="(.+)" target="_top"><img height="25" width="70"

"(.*)" is unlikely to match what you want, because .* is greedy.  Try "(.*?)"
or "([^"]*)" instead.  (I prefer the latter.)

> src="(.+)hist_p\.gif" align="absmiddle" border="0" alt="(.+)"><\/a>/<img

Same here.

> height="25" width="70" src="$2hist_p\.gif" align="absmiddle" border="0"
                              ^^^^^^^^

That's a variable named $2hist_p.  Try using ${2}hist_p instead, which
separates the variable name from the following text.

> alt="$3">/gi;
> 


It looks like all you want to do is remove the A HREF from around an image
tag.  Do you really need to match the attributes so precisely?


HTH!

Ronald

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org