From: GOTO Kentaro Date: 2002-09-24T03:33:08+09:00 Subject: Re: Problems with String#gsub! At Tue, 24 Sep 2002 02:18:07 +0900, Vincent Foley wrote: > > I have here a program to help me do crossword puzzles. Yesturday, I > added the (c) and (v) symbols to match consonants and vowels > respectivly. The problem is that they do not seem to work the way I > intend them to. Here's the program: > > [code] > #!/usr/bin/env ruby > > wordList = open('/home/vince/fr_dict.txt', 'r').read.split('\n') > repl = { > '_' => '[a-�]', > '(v)' => '[a���e���i��o��u���y]', > '(c)' => '[bcdfghjklmnpqrstvwxyz]', > '(e)' => '[�e���]' > } > > while true > print '> ' > reg = gets.chomp > repl.each_key { |token| > reg.gsub!(token, repl[token]) Try reg.gsub!(Regexp.new(Regexp.escape(token)), repl[token]) or reg.gsub!(/#{Regexp.escape(token)}/, repl[token]) W/o escape, you get /(c)/ for "(c)" and it means grouped one letter c.