I would be wary of depending on a regex that expects a rigid order of tag attributes. BrowserUk's comments about the quality of the data are well taken, and I would just modify his approach so that you can simply take any tag and parse it into its various attributes, using a hash to keep track of them, so you don't need to worry about what order they happen to have been written in:
if ( /<gene_seq ([^>]+)>/ ) { my $attribString = $1; # The challenge is to split the line properly into key/val # pairs; first, let's get rid of boundary stuff that might # get in the way: $attribString =~ s{^\s+}{}; # initial whitespace $attribString =~ s{[/\s]+$}{}; # final whitespace and/or "/" # now split into key,val pairs, assuming that " = " falls # between attrib name and attrib value, while the boundary # between a value and the next attrib name is whitespace # preceded by double-quote and followed by alphanumeric: my %attribHash = split( /\s+=\s+|(?<=\w\")\s+(?=\w)/, $attribStrin +g ); # That's it; now work with the keys and values of that hash...
Note that this preserves the double quotes around attrib values. If there's a flaw in the data, like the one that BrowserUk pointed out, this will produce a very confused result -- which you would detect if you happened to find double-quote characters in any of the hash keys. So you could follow that split with:
die "Bad xml tag:\n$_\n" if ( grep( /\"/, keys %attribHash );

In reply to Re: Regexp problems by graff
in thread Regexp problems by matth

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.