> -----Original Message-----
> From: Howie Hamlin [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, April 26, 2005 6:52 PM
> To: CF-Talk
> Subject: RegEx to manipulate html tags
> 
> Does anyone know of a regex that I can use to replace parameters in the
> tags of an html page?  For example, I would want to replace the SRC
> parameter of an <IMG> tag but the SRC parameter is not located in the same
> postition of the <IMG> tag each time.  So, as an example:
> 
> <img src="image1.jpg">
> 
> <img height="100" width="100" src="image1.jpg">
> 
> should both be converted to:
> 
> <img src="image2.jpg">
> 
> <img height="100" width="100" src="image2.jpg">
> 
> If the SRC parameter were always located after the IMG tag start (as in
> the first example) then I could use a simple findnocase but that's not the
> case.

Do you just want to get the src or are you interested in all the attributes?

If just the source then something like this should do it:

#ReReplaceNoCase(Input, "(<img.*?src.*?=.*?"").*?("".*?>)",
"\1#NewSource#\2")#

You'll have to tweak it.  I'm not even sure it'll run - but I think it will!
The power of positive thinking!

You'll have to make it more complex to also understand things like single
quotes instead of double quotes.

If you want ALL of the attributes then a nice (but, honestly, slow) way to
do it is to find all of the img tags (a regex like "<img.*?>" should do
that) rip them out of the source and treat each one like an XML doc (using
XMLParse()).

You can then navigate the tag and its attributes like an XML document.

This will only work on well formed code (so you might have to insert an end
slash if its not there.

Hope this helps,

Jim Davis




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:204626
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to