Matching multiple href="Something.aspx" using RegEx

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2007
Posts: 10
Reputation: Blackred is an unknown quantity at this point 
Solved Threads: 2
Blackred's Avatar
Blackred Blackred is offline Offline
Newbie Poster

Matching multiple href="Something.aspx" using RegEx

 
0
  #1
Jul 24th, 2007
This is really a regular expression question opposed to a .NET but I can't see any forum that specialises in that kind of thing, so as I'm using ASP.NET I figured I'd post it here

I have a string as such...

  1. <ul>
  2. <li>
  3. <a href="Welcome.aspx">Welcome</a>
  4. </li>
  5. <li>
  6. <as href="About.aspx">About us</a>
  7. </li>
  8. </ul>

And I want to match each of the href="*" and replace them, however my regular expression skills are non-existant! I've got this far...

href=".*\.aspx" but that returns just one match:

href="Welcome.aspx">Welcome</a>
</li>
<li>
<as href="About.aspx

Which isn't very useful... can anyone fix my regular expression?

Cheers,
Blackred.
This station is non-operational.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Matching multiple href="Something.aspx" using RegEx

 
0
  #2
Jul 24th, 2007
regex: href=\"[^\"]\.aspx\"

Yours was matching from the first href to the end of the second one because of the .* whereas mine allows anything except for a closing quote (and therefore stops at the end of the first one). It's not as anal as I usually get with regex, but as long as you have well-formed XHTML it should work.
Last edited by Infarction; Jul 24th, 2007 at 11:37 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC