From: Mark Thomas Date: 2008-08-13T23:37:26+09:00 Subject: Re: Regular expression: anything except On Aug 13, 10:10 am, Gunther Gunt wrote: > Hello, > > I am trying to create a regular expression with the following rule: > > my text is: > blabla > I want to replace with something > > "".gsub(/the magic regular expression/,"replacement") > ==> replacementblabla > > but i want also that > "blabla".gsub(/the magic regular expression/,"replacement") > returns the same result > ==> replacementblabla > > and > blabla".gsub(/the magic regular > expression/,"replacement") > returns the same result > ==> replacementblabla > > Can you help me ? Sure. Since it looks like XML, I recommend using an XML parser. It not a good idea to parse XML with regular expressions; doing it robustly is difficult, as there are many details that can trip you up. What you want is the text content of the TEXT element. Try this: require 'hpricot' xml = Hpricot::XML('blabla') puts xml.search("//TEXT").text # => "blabla" - Mark.