Find ampersands that are not part of an entity.

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

Find ampersands that are not part of an entity.

by Ian Skinner-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I need to search a very long string for ampersands (&) that are not part
of the non-breaking space entity ( ) and replace them with the
ampersand entity (&).

Using regex can I say select all instances of a character NOT followed
by specific other characters?



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1138
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21




Re: Find ampersands that are not part of an entity.

by Peter Boughton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>  Using regex can I say select all instances of a character NOT followed
>  by specific other characters?

Yes, it's called a negative lookahead, and looks like this: (?!...)

So to find ampersands that are not followed by nbsp; you want:
&(?!nbsp;)

This of course assumes that non-breaking spaces are the only entity
you have - will need something more complex if there are others.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1139
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21




RE: Find ampersands that are not part of an entity.

by StevenLevithan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, you can do it using a regex construct called a lookahead (in this case a negative lookahead), like so:

&(?!nbsp;)

To only match ampersands that aren't part of any entity (not just  ), you can use this:

&(?!#?\w+;)

Steve
http://blog.stevenlevithan.com

> Subject: Find ampersands that are not part of an entity.
> From: HOF@...
> To: cf-regex@...
> Date: Fri, 2 May 2008 14:14:23 -0700
>
> I need to search a very long string for ampersands (&) that are not part
> of the non-breaking space entity ( ) and replace them with the
> ampersand entity (&).
>
> Using regex can I say select all instances of a character NOT followed
> by specific other characters?
>
>
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1140
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21