Regex in HTML

So, I’m trying to write a nice bit of regex to handle finding anchor
tags in
a bit of html.

This is what I’ve got…


I’m planning on using this with a gsub!.

Here is what it has to do…

Anything in here.

As you can see, the regex I have will indeed work for this instance. It
match with ‘Anything in

Except, here is where it fails…

Anything in here.

I still need ‘Anything in here.

This regex doesn’t work…
Because my middle tag will just keep going and return

Anything in

because it doesn’t have any reason to stop.

Any suggestions?


replace .* with [^(</a)(</A)]

That should work.


You could use the ? non-greedy modifier for this:


This will match from the beginning of the <a to the first .

On 4/23/06, Hampton [email protected] wrote:

I still need '<a href=“

Family management on rails: - coming soon!
My development related blog:



This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs