Hi, I''ve got a string "foo(n_characters)". ex: foo(bar) . I would like to extract bar. What RegExp can do that? 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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jef wrote:> Hi, > > I''ve got a string "foo(n_characters)". ex: foo(bar) . > > I would like to extract bar. > > What RegExp can do that? > > thanks > > >Something like this? >> s = ''foo(bar)'' => "foo(bar)" >> myarray = s.scan(/foo\((\w+)\)/) => [["bar"]] --~--~---------~--~----~------------~-------~--~----~ 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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-May-20 15:12 UTC
Re: RegExp problem
Rory, I saw this thread and thought you might be able to point me in a RegExp direction to solve this problem. I''m importing .csv data from users'' databases and sometimes it''s UGLY with commas, pound signs, etc. I''d like to pass the string fields through some type of ''cleansing'' code that allows them to write to a MySQL string database field without COUGHING. I am grateful for any links or suggestions. Thank you, Kathleen On May 20, 3:16 am, Rory McKinley <rorymckinleyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> jef wrote: > > Hi, > > > I''ve got a string "foo(n_characters)". ex: foo(bar) . > > > I would like to extract bar. > > > What RegExp can do that? > > > thanks > > Something like this? > > >> s = ''foo(bar)'' > => "foo(bar)" > >> myarray = s.scan(/foo\((\w+)\)/) > => [["bar"]]--~--~---------~--~----~------------~-------~--~----~ 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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi everyone, I recently found Rubular [ http://www.rubular.com/ ]. It could be very helpful for playing with regexes for cleaning up that data. Regards, Craig --~--~---------~--~----~------------~-------~--~----~ 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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Rory, > I saw this thread and thought you might be able to point me in a > RegExp direction to solve this problem. > I''m importing .csv data from users'' databases and sometimes it''s UGLY > with commas, pound signs, etc. > I''d like to pass the string fields through some type of ''cleansing'' > code that allows them to write to a MySQL string database field > without COUGHING. > I am grateful for any links or suggestions. > Thank you, > Kathleen<snip> Hi Kathy Regexps may not be the ideal solution, but it very much depends on what you mean by "cleansing": a) Keeping the data intact, and making sure it will write to the DB (i.e. escaping "problem" characters so that they don''t break the insert query) or b) Actively removing/replacing stuff from the original data (e.g. replacing all the pound signs with tildes). From the little I know about ActiveRecord, Rails'' should pretty much handle (a) - but (b) would be a better fit for a regexp, depending on the degree of complexity (It''s always better to use something else other than regexps, if there is a sane alternative). Can you give some more info, on how exactly you want to cleanse the data? --~--~---------~--~----~------------~-------~--~----~ 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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Craig Demyanovich wrote:> Hi everyone, > > I recently found Rubular [ http://www.rubular.com/ ]. It could be very > helpful for playing with regexes for cleaning up that data. ><snip> Thanks for the tip Craig - looks sweet! --~--~---------~--~----~------------~-------~--~----~ 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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---