Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing non-entity ampersands only. 1

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
I'm sure this issue's come up here before, but can't find a reference.

I need to find a way to encode ampersands that are not already part of named or numeric entities.

For example,

I need to replace the & in R&B resulting in R&B but not double encode an existing entity.

Is there some snappy way I can do this with REGEX? Maybe replace any amp that is not followed by a semicolon three or four characters later? Seems less than perfect. Before I go chasing some unwieldy solution, any suggestions?
 
Code:
<%
dim str, RE
set RE=New RegExp

str = "R&B - & &amp; &#38;"
    RE.global=true
    RE.pattern="&[^#38;|amp;]"
str=RE.replace(Str,"&amp;")
%>

<%=str%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top