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 226723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:32:20+00:00 2026-05-11T19:32:20+00:00

This is more a puzzle question for my curiosity than anything else. I’m looking

  • 0

This is more a puzzle question for my curiosity than anything else. I’m looking for a single regular expression substitution that will convert entity escaped ampersands to an unescaped ampersands only within href attributes in an html file. For example:

<a href="http://example.com/index.html?foo=bar&amp;baz=qux&amp;frotz=frobnitz">
Me, myself &amp; I</a>

Would convert to:

<a href="http://example.com/index.html?foo=bar&baz=qux&frotz=frobnitz">
Me, myself &amp; I</a>

Now, I can do this in several statements but I’m curious if any perl regex gurus can do it in one.

The closest I’ve come so far is the following regex that doesn’t work because lookbehinds can’t be of variable length. Of course, it might not work even if they were allowed, I’m not sure.

s/(?<=href=".*?)&amp;(?=.*?")/&/g;

Thanks.

  • 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-05-11T19:32:21+00:00Added an answer on May 11, 2026 at 7:32 pm

    Adapting your close approximation:

    while (s/(?<=href=")([^"]*?)&amp;/$1&/) {}
    

    This is a cheat; but it is a single regex. The key part is the non-greedy scan for characters that are not a closing double quote followed by the &amp; string. The other observation to make is that given the input:

    <a href="http://example.com/index.html?x=y&amp;amp;amp;y=z">
    

    You will get out:

    <a href="http://example.com/index.html?x=y&y=z">
    

    You have to decide whether that matters.

    The difficulty with any non-iterative solution is that once you’ve read the ‘href="‘ in the first match, you won’t be seeing it again for subsequent matches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more of a puzzle than question. I have the following code: public
Disclaimer: this question may not have practical value, it's more of a puzzle/curiosity question.
Ok, I'm going to try to make this more clear because my last question
This is more of a design question. I have a template class, and I
This is more of a hypothetical question. I am wondering if anyone knows if/how
Not strictly a question, more of a puzzle... Over the years, I've been involved
I'm taking waaaayyy more classes than I normally do this semester and just haven't
this is more like a puzzle. I wanted to know if there is a
I feel that I should start this question by mentioning that I am a
I want to know this more in detail. Is it a realtime scheduler? An

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.