
HELP/QUES: regexp and strings
Hi there,
I wonder if any of you could help me out with a string manipulation
prolem I'm having, by way of code or helpful pointers? What I'm wanting
to do is this:
I have a string such as '$phrase="this is a book"', and what I'd like to
do is wrap an html tag around it such as '<span id="bk">this is a
book</span>'. The only problem is that I'm reading lines from an HTML
file, and whereas I'd like to wrap that tag around any text, I don't
want it going inside any tags already in the line, such as '<img
src="book1.gif" border=0 alt="<span...>this is a book</span> cover"
width=10 heigth=20>' would be a very bad thing.
I know how to substitute strings as in:
'$line=~s/$phrase/<span..>$phrase<\/span>/ig;' but I don't know how to
check to see if that $phrase is in a tag or not, and still output the
full $line (tags and all).
For example, the input line might be:
<td align="center"><img src="1.gif" alt="a book">This is a book. And in
a book like this there are words.</td>
the $phrase="a book" so the output should be:
<td align="center"><img src="1.gif" alt="a book">This is <span id="bk">a
book</span>. And in <span id="bk">a book</span> like this there are
words.</td>
If you can help at all I would really appreciate it. Thanks very much!
Andy