Hola Monks,

I am trying to extract the first and last Query and Subject numbers from data like the following:
><a name = 32169281></a><a href="http://www.ncbi.nlm.nih.gov/entrez/qu +ery.fcgi?cmd=Retrieve&db=Nucleotide&list_uids=32169281&dopt=GenBank" +>emb|AJ544060.1|GGA544060</a> Gallus gallus mRNA for granzyme A precu +rsor (GZMA gene) Length = 1100 Score = 721 bits (360), Expect = 0.0 Identities = 360/360 (100%) Strand = Plus / Plus + Query: 11 catgggtgtttttttcactctgtccacctctgctgccatcgttctcctgatacttcctg +g 70 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +| Sbjct: 1 catgggtgtttttttcactctgtccacctctgctgccatcgttctcctgatacttcctg +g 60 + Query: 71 agatttgtgcgtggatatcattggaggacatgaagtagcaccacactcaagaccattta +t 130 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +| Sbjct: 61 agatttgtgcgtggatatcattggaggacatgaagtagcaccacactcaagaccattta +t 120 + Query: 131 ggccatgctcaaaggaaaagaattttgtggaggagctttgatcaagccaagctgggtgt +t 190 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +| Sbjct: 121 ggccatgctcaaaggaaaagaattttgtggaggagctttgatcaagccaagctgggtgt +t 180 + Query: 191 aacagctgctcattgcaatctgaagggaggcagagttattcttggagcccattcacgga +c 250 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +| Sbjct: 181 aacagctgctcattgcaatctgaagggaggcagagttattcttggagcccattcacgga +c 240 + Query: 251 aaaaagagaagaagaagaacaggttattgagattgcagaagaaattcgctacccagact +a 310 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +| Sbjct: 241 aaaaagagaagaagaagaacaggttattgagattgcagaagaaattcgctacccagact +a 300 + Query: 311 ctgtcccgaaagaaaggaacatgacattatgctgttgaagcttaagaaaagagcaaaaa +t 370 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +| Sbjct: 301 ctgtcccgaaagaaaggaacatgacattatgctgttgaagcttaagaaaagagcaaaaa +t 360 ><a name = 16647294></a><a href="http://www.ncbi.nlm.nih.gov/entrez/qu +ery.fcgi?cmd=Retrieve&db=Nucleotide&list_uids=16647294&dopt=GenBank" +>gb|AC016999.8|</a> Homo sapiens BAC clone RP11-40B20 from 2, complet +e sequence Length = 93778 Score = 46.6 bits (23), Expect = 0.028 Identities = 23/23 (100%) Strand = Plus / Minus Query: 249 acaaaaagagaagaagaagaaca 271 ||||||||||||||||||||||| Sbjct: 64265 acaaaaagagaagaagaagaaca 64243
The results should be 249 64265 271 64243 (for the second, smaller block) and 11 1 370 360 (for the first block). I have tried this, where $id is the <a name=> number:
my @positions = $string =~ m/<a name = $id>.*?Query: (\d+).*?Sbjct +: (\d+).*?<\/pre>/s; push (@positions, $string =~ m/<a name = $id>.*?Query: \d+\s+[a-z] ++ (\d+)\n.*?\nSbjct: \d+\s+[a-z]+ (\d+)\n<\/pre>/s);
But this doesn't grab the last query properly. What can I do that avoids getting the wrong 'last' numbers? I need them from the same number block, and combinations of greedy/non-greedy matching aren't working out for me, I either get partial results (not the true last ones) or last ones from the last block in the page.

Help!

Thanks,

Evan




In reply to Regex perplexity by eweaverp

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.