OK, first here is what your substitution is doing:
s,(<[^>]+>)|(\Q$term\E),defined($1) ? $1 : "<b>$2</b>",gie
the commas are the search delimiters, so the thing being searched for is what is in between the first and second commas, and it says to look for either a tag (something that is < followed by anything that is not a > followed by a >); this is all stored in $1; or the thing that is stored in $term, this is stored in $2. Then, it does the substitution: if it found a tag, it just puts it back the way it found it, if it finds $term, it replaces it with $term in bold tags. The gie at the end makes it global (does the replacement everywhere in the string, not just the first time), case insensitive, and lets the replace part execute the code to do the conditional replace. Pressumably it searches for the tag first so that it doesn't make any replacements of $term in a tag, if that happens.

On to your question: to get it to work the way you want it to, you will have to run this substitution on just the part that you want substituted! Presumably, right now, $link_results contains everything that search.cgi is working on. You will want to break that up so that you can run the substitute only on the part you want. There are several ways to do that, and probably some that make more sense in the context of what else search.cgi is doing. If you want to copy and paste more of the code around where $link_results is generated, we could probably suggest something.

Good luck,
Scott

PS: I meant to include when writing this, that the method for search for tags (ie (<[^>]+>) is not particularly robust. I would make it at least (<[^>]+?>) to make it a minimal match, although you may have enough control over what is in $link_results to be sure it works; nevertheless, use with caution.


In reply to Re: Replacement based on pattern by scain
in thread Replacement based on pattern by drewboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.