From: Mike Stok Date: 2002-09-11T01:54:38+09:00 Subject: Re: Quick questions on using regular expressino with gsub... In article , Kurt Euler wrote: > Experts- > > Quick question: I'm trying to use the regular expression "\d" to > replace the characters "SP" followed by any single digit, with "SP" > followed by the value in a string variable. However, this technique > doesn't appear to make the desired replacements: > > pkg_base_temp.gsub!(/SP\d/, "SP"+sp_num_step) > > is the target string "/SP\d/" not written correctly? What error message are you getting? It may be that you're expecting perlish number <=> string magic to happen e.g. pkg_base_temp = "fooSP2bar" sp_num_step = 5 pkg_base_temp.gsub!(/SP\d/, "SP"+sp_num_step) => boom! as 5 is not a string (TypeError: cannot convert Fixnum into String). If this is the problem then pkg_base_temp.gsub!(/SP\d/, "SP" + sp_num_step.to_s) or pkg_base_temp.gsub!(/SP\d/, "SP#{sp_num_step}") might be useful. Hope this helps, Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA