CodingRegular expression help

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  THERE IS NO GOD BUT (RENDLE)  
 To:  ALL
33375.1 

Hello. I need a regular expression which can replace & with &, but only if it occurs in an href attribute. Which is to say, this:

 

<a href="http://localhost/?a=1&amp;z=2">Fish &amp; Chips</a>

 

should become

 

<a href="http://localhost/?a=1&z=2">Fish &amp; Chips</a>

 

I could probably work it out, given an afternoon and an ounce of cocaine, but I have neither. Virtual bumlove to anyone who [does/can but doesn't]* help.

 


*delete according to how you feel about bumlove.


There are two types of creationist: morons and liars.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  THERE IS NO GOD BUT (RENDLE)     
33375.2 In reply to 33375.1 
There's probably a cleverer way, but assuming this is a one-off fix, I'd be inclined to just repeat the following a handful of times:

href="([^"]*)&([^"]*)"
href="\1&\2"

(Might be href="$1&$2" for some regex engines)
0/0
 Reply   Quote More 

 From:  DarkBadger  
 To:  THERE IS NO GOD BUT (RENDLE)     
33375.3 In reply to 33375.1 
code:
Please replace &amp; with &, but only if it occurs in an href attribute.


Seems regular enough to me.
0/0
 Reply   Quote More 

 From:  THERE IS NO GOD BUT (RENDLE)  
 To:  Peter (BOUGHTONP)     
33375.4 In reply to 33375.2 
Thank you.

There are two types of creationist: morons and liars.
0/0
 Reply   Quote More 

Reply to All    
 

1–4

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats