From: Calvin Bornhofen Date: 2012-12-24T08:19:32+09:00 Subject: Re: trying to strip characters from a line Hello, it did not work, because his regular expression is describing a different pattern than you want: The \["\], looks for a [ (must be escaped in the regular expression, because it is a character with special meaning), followed by a ", followed by a ] (as with [), followed by a ,. His regular expression worked in his case, because he had ["], in his string. You want, as far as I can tell, remove all occurrences of those characters. The regular expression you want is similar: /[\[\]",]/ If you don't know what this does, here's an explanation: The [ denotes the beginning of a set, and the ] ends it. The set matches to any character inside of it, but only one (because I did not write a quantifier like * or + after it). So, this works: "A[Aaa[]aa, \"aa".gsub( /[\[\]",]/, '' ) # => "AAaaaa aaa" Alternatively, you could describe what you want with the regular expression /\[|\]|"|,/ since the pipe in regular expressions can be read as "or". Regards (Tested in Ruby 1.9.3p286; I don't know from the top of my head if the behavior would be any different in 1.8) On 23.12.2012 21:01, Paul Mena wrote: > Strangely, this didn't work for me: > > irb(main):001:0> '["the frustrated musician’s
mountain
of > unsold CDs
", "Feb-12-2012"]
'.gsub(/\["\],/,'') > > => "[\"the frustrated musician’s
mountain
of unsold > CDs
\", \"Feb-12-2012\"]
" >