This will probably seem simple to you folks out there. Unfortunately, it's not for me. Here it goes...
I've got this site search engine. Works real good. Fast enough, etc. When a user selects a document or page from the list of search results, another script is supposed to hilight or mark the search query so that when they are reading the page, the search query pops out at them.
I have a chunk of code that does the replacement $word with <htmlcode>$word</htmlcode>. That works just fine.
To ensure that html wouldn't be screwed up, my search script also strips all html from the file its searching (not writing to disk, just while its searching). This way, the html code won't produce invalid results (like searching for 'font' or 'table' etc.) so the replacement afterwards doesn't conflict with the HTML (like
<<htmlcode>font color=blue>some text</htmlcode>font</htmlcode>>).
This may not sound like such an issue until one searches for something like webmaster, which is not only in pages as normal text, but also in HTML. When I search for webmaster, I get the following screwed up HTML:
<a href="mailto:<htmlcode>webmaster</htmlcode>@domain.com"><htmlcode>webmaster</htmlcode>@domain.com</a>.
Anyway, to make a long story short, is there a way to negate a regexp so that a string replacement happens when something isn't true? Like 'don't replace this text if its inside < and > (a tag attribute)?? Or is there an easier way to do this?
Any help would be appreciated.
Jason
tisource_webmaster@yahoo.com
Edit by tye
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.