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 like a puzzle. I wanted to know if there is a
i am implementing puzzle game application in this application create one button in click
OK, the question title is a bit crappy, but I didn't really know how
I'm going to write a simple animation in XPCE ( four glasses puzzle to
Ain't it true that while counting the moves for 1 tile can lead to
I've written a gevent -based program that allows its web clients to quickly exchange
I am developing an app that lets the user record videos and photos. Now
I would like to solve/implement the 8 puzzle problem using the A* algorithm in
Introduction A valid Sudoku grid is filled with numbers 1 to 9, with no
I am making a 2d space game with many moving objects. I have already

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.