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.s,(<[^>]+>)|(\Q$term\E),defined($1) ? $1 : "<b>$2</b>",gie
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |