Gsub, help please

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

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

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

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!!

Thanks :slight_smile:

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!!