From: Rousan Malik Date: 2011-07-18T04:34:10+09:00 Subject: Re: replace string between xml tags that contains special characters Thank you all for the response. I will try to elaborate on this. All I want is to parse an xml file which contains special characters. But my parser fails because it cannot open the file correctly (because of the special characters). So I decided to write the file contents to a new file by removing the special characters and then parse it. My sample input file(input.xml) with special characters is as follows: Validating element: %F0wt^϶b%99%90%94%D4N%8D%FA%8A%EE%81_ ޢg%9B@I%E3%F6%FCp%AFX%BD%80%91%B5pEK%C9!j%D3%F3SY%C3%F6B~%C8%FC ^%87%C4%F2]! %B9%DF=%E7Y%B9 My desired output file(output.xml) should be something like this: TEXT REMOVED I have the following code in place in an attempt to do this: ------------------------------------------------------------ fin = File.new("input.xml", "rb") fout = File.new("output.xml", "w") while (line = file.gets) temp = line.gsub(/\Validating element:(.*?)\<\/message\>/, 'TEXT REMOVED') fout.puts "#{temp}" end fin.close fout.close ------------------------------------------------------------ But the above code replaces the "....." content all together and my output.xml file is: My problem is solved as I am not using the message tag in my parser. But ideally I want to remove only the content between the message tag without removing the tag all together. If anyone knows how to do it(preferably in a single line) please share it with me. Thanks in Advance, Rousan -- Posted via http://www.ruby-forum.com/.