Forum: Ruby on Rails Regex in HTML

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Hampton (Guest)
on 2006-04-24 05:09
(Received via mailing list)
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....

<html><a href="" class="link">Anything in

As you can see, the regex I have will indeed work for this instance. It
match with '<a href="" class="link">Anything in

Except, here is where it fails....

<html><a href="" class="link"><strong>Anything</strong>

I still need '<a href=""
class="link"><strong>Anything</strong> in here.</a>'

This regex doesn't work...
Because my middle tag will just keep going and return

<a href="" class="link"><strong>Anything</strong> in

because it doesn't have any reason to stop.

Any suggestions?

unknown (Guest)
on 2006-04-24 05:30
(Received via mailing list)
replace .* with [^(<\/a)(<\/A)]

That should work.

Just S. (Guest)
on 2006-04-24 05:36
(Received via mailing list)
You could use the ? non-greedy modifier for this:


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

On 4/23/06, Hampton <removed_email_address@domain.invalid> wrote:
> I still need '<a href=""

Family management on rails: - coming soon!
My development related blog:
Hampton (Guest)
on 2006-04-24 06:03
(Received via mailing list)

This topic is locked and can not be replied to.