# Regexp.escape the href values

**URL:** <https://www.ruby-forum.com/t/regexp-escape-the-href-values/138722>\
**Category:** Rails\
**Created:** [May 27, 2008, 8:45am UTC](https://www.ruby-forum.com/t/regexp-escape-the-href-values/138722 "2008-05-27T08:45:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vidyagayathri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ba9def/32.png) [@vidyagayathri](https://www.ruby-forum.com/u/vidyagayathri)\
**Post date:** [May 27, 2008, 8:45am UTC](https://www.ruby-forum.com/t/regexp-escape-the-href-values/138722/1 "2008-05-27T08:45:54Z")

</div>

Hi All,

```
I want the skip the href values which is inside , while doing rake

```

task. but i am getting out put like this.

my text = rails

Rails is the keyword, but if already got linked, it should not link  
again.

but i am getting output like this.

\<a href=“[Rails](http://localhost/dest/rails)”\>rails

its linking inside again.

for this i have used the Regexp.escape. but its not working as expected.

def match\_string(s)  
/(#{Regexp.escape(s)})(?!([^(\<a)]\*\</a\>)|(/)|\w)/  
end

So, Please advise me, if anyone knows ASAP.

---

<div class="post-metadata">

**Author:** ![vidyagayathri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ba9def/32.png) [@vidyagayathri](https://www.ruby-forum.com/u/vidyagayathri)\
**Post date:** [May 27, 2008, 10:53am UTC](https://www.ruby-forum.com/t/regexp-escape-the-href-values/138722/2 "2008-05-27T10:53:03Z")

</div>

On May 27, 7:45 am, Vidya V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> end

This rather muddled. You haven’t really explained what the input is,  
what the expected output is and exactly what that regular expression  
is trying to match

Fred

---

<div class="post-metadata">

**Author:** ![vidyagayathri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ba9def/32.png) [@vidyagayathri](https://www.ruby-forum.com/u/vidyagayathri)\
**Post date:** [May 27, 2008, 11:36am UTC](https://www.ruby-forum.com/t/regexp-escape-the-href-values/138722/3 "2008-05-27T11:36:36Z")

</div>

Hi Fred,

```
Thanks for your reply.

```

My input will be:

```
 "The lion is the largest African carnivore. It is a sandy to tawny 

```

coloured cat with white under parts on which females often retain  
rosettes and spots characteristic of younger animal.then the last one is  
test

The keywords are : lion, animals, african, Tiger.

So my expected output are , when i am running the task , should be  
linked the keywords with href. but except which is in href already.

Expected Output:

"The lion is the largest African carnivore. It is a sandy to tawny  
coloured cat with white under parts on which females often retain  
rosettes and spots characteristic of younger animal.then the last one is test

But right now i am getting like:

“The lion is the largest African carnivore. It is a sandy to tawny  
coloured cat with white under parts on which females often retain  
rosettes and spots characteristic of younger animal.then the last one is \<a href=”Tiger"\>test

Note: See i am getting link twice , inside the href again and again.

it should not link , which is inside the href.

I hope u understand now.

Frederick C. wrote:

> On May 27, 7:45ï¿½am, Vidya V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > ï¿½end
> 
> This rather muddled. You haven’t really explained what the input is,  
> what the expected output is and exactly what that regular expression  
> is trying to match
> 
> Fred

---

<div class="post-metadata">

**Author:** ![vidyagayathri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ba9def/32.png) [@vidyagayathri](https://www.ruby-forum.com/u/vidyagayathri)\
**Post date:** [May 27, 2008, 6:16pm UTC](https://www.ruby-forum.com/t/regexp-escape-the-href-values/138722/4 "2008-05-27T18:16:03Z")

</div>

Linker should ignore keywords inside of hyperlinks

Example:

Tiger is a animal.

This text should be not link which is inside link tag.

Tiger is a animal.

But right now i am getting like

\<a href=“animalAnimal”\>Tiger is a animal.

Does it make sense?

Frederick C. wrote:

> On 27 May 2008, at 10:36, Vidya V. wrote:
> 
> > it should not link , which is inside the href.
> 
> that makes sense, what doesn’t make any sense is your regular  
> expression. What were you trying to make it do?
> 
> Fred

---

<div class="post-metadata">

**Author:** ![vidyagayathri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ba9def/32.png) [@vidyagayathri](https://www.ruby-forum.com/u/vidyagayathri)\
**Post date:** [May 27, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/regexp-escape-the-href-values/138722/5 "2008-05-27T18:27:00Z")

</div>

On 27 May 2008, at 17:16, Vidya V. wrote:

> But right now i am getting like
> 
> \<a href=“animalAnimal”\>Tiger is a animal.

I got that first time round. What i don’t know is how you’re trying to  
use that regular expression. a little more of your code would clarify  
matters.

Fred

---

<div class="post-metadata">

**Author:** ![vidyagayathri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ba9def/32.png) [@vidyagayathri](https://www.ruby-forum.com/u/vidyagayathri)\
**Post date:** [May 27, 2008, 11:50am UTC](https://www.ruby-forum.com/t/regexp-escape-the-href-values/138722/6 "2008-05-27T11:50:50Z")

</div>

On 27 May 2008, at 10:36, Vidya V. wrote:

> it should not link , which is inside the href.

that makes sense, what doesn’t make any sense is your regular  
expression. What were you trying to make it do?

Fred
