From: Vincent Foley Date: 2002-09-24T02:18:07+09:00 Subject: Problems with String#gsub! 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]) } reg = '^' << reg << '$' puts reg for word in wordList puts word if word =~ reg end end [/code] And here's a sample session where it does not do what I expect it to (and gives wrong results): [quote] [vince@vincent: ~/prog/ruby]% ./crosswords.rb > (c)(v)(v) ^([bcdfghjklmnpqrst[a���e���i��o��u���y]wxyz])([a���e���i��o��u���y])([a���e���i��o��u���y])$ > [/code] I would've expected my regular expression to be: ^[bcdfghjklmnpqrstvwxyz][a���e���i��o��u���y][a���e���i��o��u���y]$ Why did it keep the parenthesis? Why did it replace the v with the complet vowel set? Thanks for you help, Vince -- Vincent Foley-Bourgon Email: vinfoley@iquebec.com Homepage: http://darkhost.mine.nu:81