RegExp Replace, except inside an HTML tag

View: New views
3 Messages — Rating Filter:   Alert me  

RegExp Replace, except inside an HTML tag

by schnee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have a piece of text containing HTML code.
I want to replace (in Javascript) what matches a RegExp, but NOT if the
match is inside an HTML tag.
Is it possible without slicing the text into pure text and HTML parts?

For instance:
replace (/"([^"]*?)"/, "? $1 ?")
replaces "quoted text" with ? quoted text ?
But it should not replace
<TD width="100">
with <TD width=? 100 ?>

Any hint?

--
_______________________________________
REUSE CODE! Use custom tags;
See http://www.contentbox.com/claude/customtags/tagstore.cfm
(Please send any spam to this address: piegeacon@...)
Thanks.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:21:923
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/21
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:21
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Re: RegExp Replace, except inside an HTML tag

by Ben Doom :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't think so.  IIRC, JS regex doesn't support negative lookaheads
and lookbehinds, which are really my only idea.  Sorry.

--Ben

Claude Schneegans wrote:

> Hi,
>
> I have a piece of text containing HTML code.
> I want to replace (in Javascript) what matches a RegExp, but NOT if the
> match is inside an HTML tag.
> Is it possible without slicing the text into pure text and HTML parts?
>
> For instance:
> replace (/"([^"]*?)"/, "? $1 ?")
> replaces "quoted text" with ? quoted text ?
> But it should not replace
> <TD width="100">
> with <TD width=? 100 ?>
>
> Any hint?
>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

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

Re: RegExp Replace, except inside an HTML tag

by schnee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 >>I don't think so.

I was affraid to find (at last) something I couldn't do with regex ;-/

Thanks.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

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