[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: confused by back refs in gsub

Simon Krahnke

8/13/2007 9:51:00 PM

* Felix Windt <fwmailinglists@gmail.com> (22:18) schrieb:

> I'm leaving off the opening bracket '<':
>
> line.gsub!(/registrantName>/, 'SUB.HEAD4>')
>
> So that it will match the opening as well as closing statement.

As well as any substring "registrantName>". And well-formed XML won't
guarantee that only "<registrantName>" and "</registrantName>" will
contain that.

gsub!(/(<\/?)registrantName>/, '\1SUB.HEAD4>') should do.

But again, CDATA-sections and comments may well contain these strings.
I'd use XSLT or some SAX-Library if it has to be ruby.

mfg, simon .... l
1 Answer

Peter Bailey

8/14/2007 11:32:00 AM

0

Simon Krahnke wrote:
> * Felix Windt <fwmailinglists@gmail.com> (22:18) schrieb:
>
>> I'm leaving off the opening bracket '<':
>>
>> line.gsub!(/registrantName>/, 'SUB.HEAD4>')
>>
>> So that it will match the opening as well as closing statement.
>
> As well as any substring "registrantName>". And well-formed XML won't
> guarantee that only "<registrantName>" and "</registrantName>" will
> contain that.
>
> gsub!(/(<\/?)registrantName>/, '\1SUB.HEAD4>') should do.
>
> But again, CDATA-sections and comments may well contain these strings.
> I'd use XSLT or some SAX-Library if it has to be ruby.
>
> mfg, simon .... l

Thank you, everyone. Yes, my XML is well-formed, but, it's also pretty
simple, and, from what our vendor tells me, pretty consistent. I just
need to convert it to SGML for our company publishing system. XSLT is
probably better for this, I'm sure, but, it's enough for me just to
learn Ruby. (-: Plus, I love Ruby.
Thanks again.
--
Posted via http://www.ruby-....