I''m writing this simple substitution method and I have a <textarea> providing me with the input text. I have some multiline text: This is a *test* ok? Which I pass through to my async method in the variable @text. In the method, my regular expression and gsub matches anything between asterisks, and put it in brackets: @text.gsub!(/\*(.*?)\*/m, ''<\1>'') And this yields: This is a <test> ok? How can I get my regexp to stop eating the newlines? As you can see, I have the multiline flag on. Am I missing something within the actual regexp? Help would be greatly appreciated. Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This is odd, as running in irb yields the following: irb(main):001:0> s = "This is\na *test*\nok?" => "This is\na *test*\nok?" irb(main):002:0> s.gsub(/\*(.*?)\*/m, ''<\1>'') => "This is\na <test>\nok?" irb(main):002:0> puts s.gsub(/\*(.*?)\*/m, ''<\1>'') This is a <test> ok? Here is my Ruby version: david@redclay ~ $ ruby -v ruby 1.8.5 (2006-08-25) [i686-linux] I wonder why it works for me in irb, but not for you in your controller? I also ran it in script/console with Rails 1.2.3, and everything was golden. On 5/19/07, Whitedot <whitedotstudios-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I''m writing this simple substitution method and I have a <textarea> > providing me with the input text. I have some multiline text: > > This is > a *test* > ok? > > Which I pass through to my async method in the variable @text. > In the method, my regular expression and gsub matches anything between > asterisks, and put it in brackets: > > @text.gsub!(/\*(.*?)\*/m, ''<\1>'') > > And this yields: > > This is a <test> ok? > > How can I get my regexp to stop eating the newlines? As you can see, I > have the multiline flag on. Am I missing something within the actual > regexp? Help would be greatly appreciated. Thanks! > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
alexander-0M91wEDH++c@public.gmane.org
2007-May-20 03:58 UTC
Re: Substitutions without eating newlines
dear sender, i´m out of the office until may 29th. your email will not be forwarded. for urgent stuff please contact joern-0M91wEDH++c@public.gmane.org kind regards, alexander --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---