Hi Perlmonks,

I am interested to get all the possible matches from a string using regex. But I have got fewer matches than expected with the perl script g1.pl. I have given the script, the incorrect results and the expected results below. I request perlmonks to provide suggestions how to write the regex to get the correct results.

Here goes the script:

#!/usr/bin/perl use warnings; $seq="TT TATAAT CGCG ATG CAG GAG TGG TAA TGA TAG CC TGA TATAAT CCC A +TG CTA CAT TGA TT"; $seq=~ s/\s//gs; while ($seq=~ /([AG]TG).*?(TAA|TAG|TGA)+?/gs) { my $match=$&; $match=~ s/\s//g; push @matches,$match;} print"\n Matches are:\n\n"; print join ("\n",@matches); print"\n\n"; exit;

I have got the incorrect results like:

C:\Users\Dr Supriyo>cd desktop C:\Users\Dr Supriyo\Desktop>g1.pl Matches are: ATGCAGGAGTGGTAA ATGCTACATTGA

The correct results should be:

Matches are:
ATGCAGGAGTGGTAA ATGCAGGAGTGGTAATGA ATGCAGGAGTGGTAATGATAG ATGCAGGAGTGGTAATGATAGCCTGA ATGCTACATTGA

In reply to How does one get all possible matches from regex? by supriyoch_2008

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.