Back again with another question :-) I have XML of this form
<heading level=2> Introduction to Arguments</heading>
and
<heading> <index primary-key="procedures" secondary-key="definition, rest ar +guments in"/> <index primary-key="rest arguments" secondary-key="specifying, in +procedure definition"/> level=3, Specifying Rest Arguments in a Procedure Definition</heading>
And I would like to integrate the "level" attribute into the <heading> tag, so that the first would become
<heading2> Introduction to Arguments</heading2>
and the second would become
<heading3> <index primary-key="procedures" secondary-key="definition, rest ar +guments in"/> <index primary-key="rest arguments" secondary-key="specifying, in +procedure definition"/> Specifying Rest Arguments in a Procedure Definition</heading3>
To do this I've written a regex which, unfortunately, fails to work. Here's my regex:
$text =~ s/<heading([^(<\/heading>)]*?)level=(.{1})([^(<\/heading>)]*? +)<\/heading>/<heading$2>$1$3<\/heading$2>/gsix;
Any hints on where my logic goes astray? Thanks for any and all info, sorry to bother everyone with such a simple question.

In reply to Regex for XML attributes... by tshabet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.