473,796 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search and Replace while ignoring HTML formatting?

I have a search program that returns an HTML string which I display to
the user. I want to highlight the search terms. However a simple
search and replace on the HTML causes problems.

If the user searches on Georgia and I get back this:
<div style="font-name:Arial">Geo rgia, Alabama, and Louisiana</div>

It works fine:
<div style="font-name:Arial"><sp an style="backgrou nd-
color:yellow;"> Georgia</span>, Alabama, and Louisiana</div>

However if the HTML that comes back is this:
<div style="font-name:Georgia">G eorgia, Alabama, and Louisiana</div>

I get a serious problem which breaks the formatting and looks
terrible:
<div style="font-name:<span style="backgrou nd-color:yellow;"> Georgia</
span>"><span style="backgrou nd-color:yellow;"> Georgia</span>, Alabama,
and Louisiana</div>

The HTML I'm getting back is quite complex, with nested spans, style
tags, etc. I'm stuck for how to solve this problem - is there a
regular expression I can use to match chunks of non-formatting text to
replace? I have neither the time nor the resources to write a full
blown html tokenizer.

Jul 24 '07 #1
1 1389
You will probably want to use XHTML instead of HTML and use an XML parser to
do the work. You should be able to loop through text nodes and apply the
search/replace there.
"Josiwe" <jo************ ***@gmail.comwr ote in message
news:11******** **************@ z24g2000prh.goo glegroups.com.. .
>I have a search program that returns an HTML string which I display to
the user. I want to highlight the search terms. However a simple
search and replace on the HTML causes problems.

If the user searches on Georgia and I get back this:
<div style="font-name:Arial">Geo rgia, Alabama, and Louisiana</div>

It works fine:
<div style="font-name:Arial"><sp an style="backgrou nd-
color:yellow;"> Georgia</span>, Alabama, and Louisiana</div>

However if the HTML that comes back is this:
<div style="font-name:Georgia">G eorgia, Alabama, and Louisiana</div>

I get a serious problem which breaks the formatting and looks
terrible:
<div style="font-name:<span style="backgrou nd-color:yellow;"> Georgia</
span>"><span style="backgrou nd-color:yellow;"> Georgia</span>, Alabama,
and Louisiana</div>

The HTML I'm getting back is quite complex, with nested spans, style
tags, etc. I'm stuck for how to solve this problem - is there a
regular expression I can use to match chunks of non-formatting text to
replace? I have neither the time nor the resources to write a full
blown html tokenizer.
Jul 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8733
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast, returned the hyperlinked page title, filename, and the body txt (30 preceding and following words) in context with the search word highlighted. Excellent.! See it working at: http://www.ipt.co.za Just search for "firearm"
4
1404
by: Rob Meade | last post by:
Lo all, Ok - just spotted another problem I'm going to have. All of the rows for the page content in the database contain formatting ie, <b>some bold text</b> This will cause me a problem initially as if I wanted to search for <company name> the SQL statement
23
7002
by: SeaPlusPlus | last post by:
I want to convert large files of prose to xhtml and so I need a way to remove unwanted line wraps. So, I'm looking for a freebee editor that has the capability of searching for a single "carriage return/line feed" or "line feed/carriage return" and removing them. I quess what I need is an editor that allows non-printable characters in it's search strings. Does anyone know of on that will allow this? Thank you...
83
5970
by: D. Dante Lorenso | last post by:
Trying to use the 'search' in the docs section of PostgreSQL.org is extremely SLOW. Considering this is a website for a database and databases are supposed to be good for indexing content, I'd expect a much faster performance. I submitted my search over two minutes ago. I just finished this email to the list. The results have still not come back. I only searched for: SECURITY INVOKER
32
14903
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
4
4840
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional way mean to secrife lots of time in asp.net. can any one give me such a expression in which i pass a data string and search word string and replace word string? if so plz help me out. i'm in badly need.
2
5116
by: Dennis | last post by:
I am trying to implement a "Find and Replace" dialog that allows using wildcards in the find string, much like the Find and Replace Dialogs in Ms Word, etc. Are there any references or examples on this. I have tried using the Like comparision operator but about all I can do with it is replace a whole string that contains the wildcard search string. I want to do something like finding *mysea?rch in a string like "This is mysearch string...
5
2155
by: foolproofplan | last post by:
Hey everyone. I am running into a problem with unique ids that need to be compared in two xml files. The actual object name is represented with its unique id later in the xml file, so i need to do a search on an id, find its name, and then replace the original id with the name instead. If this doesn't make much sense, here is an example: <DBViewer template_id=" .... /> <Fruits type="ObjectLink" >:1170775272:459887139:</Fruits>...
1
7553
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and having the sql statement dynamically built according to the input provided by the user. I have used the method described here hundreds of times it is quick and adaptive. I generally use a frames page for the search, in this way the search is maintained...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10201
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.