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.
A77873df3a9766b208e009248a2a9a56?d=identicon&s=25 Hampton (Guest)
on 2006-04-24 03: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?

D5145c421cd25af6fa577c15219add90?d=identicon&s=25 unknown (Guest)
on 2006-04-24 03:30
(Received via mailing list)
replace .* with [^(<\/a)(<\/A)]

That should work.

Cbff7ea94c9b2c4d5f7cfefd25be9ae2?d=identicon&s=25 Just Someone (Guest)
on 2006-04-24 03: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 <> wrote:
> I still need '<a href=""

Family management on rails: - coming soon!
My development related blog:
A77873df3a9766b208e009248a2a9a56?d=identicon&s=25 Hampton (Guest)
on 2006-04-24 04:03
(Received via mailing list)

This topic is locked and can not be replied to.