From: Stefano Crocco Date: 2007-08-14T05:15:00+09:00 Subject: Re: confused by back refs in gsub Alle luned狸 13 agosto 2007, Peter Bailey ha scritto: > Felix Windt wrote: > >> I've tried "\1" instead of "\&," too. Same result. I've also > > > > If you're hardcoding replacements like that and are certain that your > > source > > is well formed xml, you could also just skip the back references: > > > > irb(main):001:0> "Normandy Group > > LLC".gsub!(/registrantName>/, 'SUB.HEAD4>') > > => "Normandy Group LLC" > > irb(main):002:0> > > I don't quite understand your suggestion, Felix. Yes, I believe my > source data is well-formed XML. Are you suggesting that, somehow, > because it is well-formed XML, I can ignore the element closings? I > tried what I thought you meant by: > > xmlfile.gsub!(//, '') > > and, I got the subhead callout at the beginning of the data, but, the > closing element still is there--/ > > -Peter What Felix is suggesting is that, if the source is valid XML, then it will have the form text so, if you call gsub! passing a regexp matching elementName>, it should replace both the opening and closing tags. When you tried, it didn't work because you left the opening < in the regexp, which didn't match the closing tag (it starts with /, 'SUB.HEAD4>') (by the way, notice that the regexp doesn't match the starting '<', so it gets removed from the replacement string) I hope this helps Stefano