What characters have to be escaped within a [] in a regular
expression? I was a bit taken aback by the following:
irb(main):001:0> a = '!#$%^&(()_GHF$%#$^%&;2~)+|{}|{\’
=> "!#$%^&(()_GHF$%#$^%&;2~)+|{}|{\"
irb(main):002:0> a.gsub(/[!@#$%^&+={}|\]/, ‘_’)
SyntaxError: compile error
(irb):2: parse error, unexpected $undefined.
a.gsub(/[!@#$%^&+={}|\]/, ‘’)
^
(irb):2: parse error, unexpected $undefined.
a.gsub(/[!@#$%^&*+={}|\]/, '’)
^
(irb):2: parse error, unexpected ‘)’, expecting $
from (irb):2
irb(main):003:0> a.gsub(/[!@#$%^&+={}|\]/, '’)
=> "#$(()__GHF$#$;2~__)_____"
irb(main):004:0> a.gsub(/[!@#$%^&+={}|\]/, '’)
=> "(()GHF______;2~__)__"
martin