# Gsub, help please

**URL:** <https://www.ruby-forum.com/t/gsub-help-please/93035>\
**Category:** Rails\
**Created:** [April 26, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/gsub-help-please/93035 "2007-04-26T20:04:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 26, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/gsub-help-please/93035/1 "2007-04-26T20:04:32Z")

</div>

ok, been going on this for an hour now, and can not find a solution

I want to find all content between ` tags in a string and replace
the content of these with new formatted content. Any suggestions why the
following code is not working?`

self.content = self.content.gsub(/`(.*?)</code>/, ‘new content’)`

Cheers  
Josh

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 26, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/gsub-help-please/93035/2 "2007-04-26T20:51:21Z")

</div>

On Apr 26, 2007, at 20:04 , josh wrote:

> I want to find all content between ` tags in a string and replace
> the content of these with new formatted content. Any suggestions
> why the
> following code is not working?`
> 
> `
> self.content = self.content.gsub(/(.*?)</code>/, ‘new content’)
> 
> `

`
Nope, because it is working:
irb(main):026:0> “This is stuff”.gsub(/(.*?)</
code>/, ‘new content’)
=> “This is new content”

You need to provide more details and code if you’re experiencing
something different.
–
Jakob S. - http://mentalized.net`

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 26, 2007, 9:15pm UTC](https://www.ruby-forum.com/t/gsub-help-please/93035/3 "2007-04-26T21:15:07Z")

</div>

Hi,

Last comment got me thinking and after testing of the code, and have  
found that it breaks if there is a new line ‘\n’ within the `. Does
anyone know how to get the (.*?) to accept new lines ( \n )`

`
thanks
josh
Jakob S. wrote:

On Apr 26, 2007, at 20:04 , josh wrote:

I want to find all content between tags in a string and replace
the content of these with new formatted content. Any suggestions
why the
following code is not working?

self.content = self.content.gsub(/(.*?)</code>/, ‘new content’)

Nope, because it is working:
irb(main):026:0> “This is stuff”.gsub(/(.*?)</
code>/, ‘new content’)
=> “This is new content”

You need to provide more details and code if you’re experiencing
something different.
–
Jakob S. - http://mentalized.net

`

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 26, 2007, 9:27pm UTC](https://www.ruby-forum.com/t/gsub-help-please/93035/4 "2007-04-26T21:27:25Z")

</div>

Hi,

> found that it breaks if there is a new line ‘\n’ within the `. Does anyone know how to get the (.*?) to accept new lines ( \n )`
> 
> `
> `

`
you can set a multiline regexp pattern by adding m after the pattern,
like in /.*/m
regards,
javier ramirez

–
Estamos de estreno… si necesitas llevar el control de tus gastos
visita http://www.gastosgem.com !!Es gratis!!`

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 26, 2007, 9:36pm UTC](https://www.ruby-forum.com/t/gsub-help-please/93035/5 "2007-04-26T21:36:37Z")

</div>

Thanks 🙂

javier ramirez wrote:

> Hi,
> 
> > found that it breaks if there is a new line ‘\n’ within the `. Does anyone know how to get the (.*?) to accept new lines ( \n )`
> > 
> > `
> > `
> 
> `
> you can set a multiline regexp pattern by adding m after the pattern,
> like in /.*/m
> regards,
> javier ramirez
> –
> Estamos de estreno… si necesitas llevar el control de tus gastos
> visita http://www.gastosgem.com !!Es gratis!!
> `
