Hi,
I've got a string "foo(n_characters)". ex: foo(bar) .
I would like to extract bar.
What RegExp can do that?
thanks
Hi,
I've got a string "foo(n_characters)". ex: foo(bar) .
I would like to extract bar.
What RegExp can do that?
thanks
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"]]
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
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
KathysKode@gmail.com 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?
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!