Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9079609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:52:32+00:00 2026-06-16T19:52:32+00:00

I need to replace all & with with & in a string like this:

  • 0

I need to replace all & with with & in a string like this:

Übung 1: Ü & Ä

or in html

Übung 1: Ü & Ä

Like you see htmlspecialchars in the string (but the & is not displayed as &), so I need to exclude them from my replace. I’m not so familiar with regular expressions. All I need is an expression that does the following:

Search for & that does either follow a (space) or does not follow some chars, excluding a space, which are ending with a ;. then replace that with &.

I tried something like this:

<cfset data = ReReplace(data, "&[ ]|[^(?*^( ));]", "&amp;", "ALL") />

but that replaces every char with the $amp;… ^^’

Sorry, I really don’t get that regex things.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:52:33+00:00Added an answer on June 16, 2026 at 7:52 pm

    Problem with existing attempt

    The reason your attempted pattern &[ ]|[^(?*^( ));] is failing is primarily because you have a | but no bounding container – this means you are replacing &[ ] OR [^(?*^( ));] – and that latter will match most things – you are also misunderstanding how character classes work.

    Inside [..] (a character class) there are a few simple rules:

    • if it starts with a ^ it is negated, otherwise the ^ is literal.
    • if there is a hyphen it is treated as a range (e.g. a-z or 1-5 )
    • if there is a backslash, it either marks a shorthand class (e.g. \w), or escapes the following character (inside a char class this is only required for [ ] ^ - \).
    • you are only matching a single character (subject to any qualifiers); there is no ordering/sequence inside the class, and duplicates of the same character are ignored.

    Also, you don’t need to put a space inside a character class – a literal space works fine (unless you are in free-spacing comment mode, which needs to be explicitly enabled).

    Hopefully that helps you understand what was going wrong?

    As for actually solving your problem…

    Solution

    To match an ampersand that does not start a HTML entity, you can use:

    &(?![a-z][a-z0-9]+;|#(?:\d+|x[\dA-F]+);)
    

    That is, an ampersand, followed by a negative lookahead for either of:

    • a letter, then a letter or a number, the a semicolon – i.e. a named entity reference

    • a hash, then either a number, or an x followed by a hex number, and finally a semicolon – i.e. a numeric entity reference.

    To use this in CFML, to replace & with &amp; would be:

    <cfset data = rereplaceNoCase( data , '&(?![a-z][a-z0-9]+;|##(?:\d+|x[\dA-F]+);)' , '&amp;' , 'all' ) />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so if I have this pattern: ab&bc&cd&de&ef And I need to replace all
I have a string and I need to replace all the &#39; and etc
wondering how I can replace all special chars on my string like: hello this
I need to replace all System.Environment.Newline(s) in the string returned by my function with
I need a one line gsub to replace all the non-digits in a string
I need to replace all special control character in a string in Java. I
Say I have a string that looks like this: str = The &yquick &cbrown
I've got a string and I'm trying to replace all &nbsp within tags with
I have a string with special characters like this: äöüß& Now I want to
I'm trying to do something like this... f = f.replace(' ',' &#160; ','gi'); I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.