Hi all!

I'm trying to match a slightly variable pattern and I don't get the point what I'm doing wrong. My pattern looks like this:

u70475_s_at<MAYBE_WHITESPACE><TAB>Mus musculus p45 NF-E2 related factor 2 NRF2 gene exon 2 to exon 5 and complete cds.<MAYBE_WHITESPACE><TAB>2326<MAYBE_TAB>727.3

The second number is optional, numbers can be float or integer.
I try to match the pattern like that:

$_[0] =~ m/([a-zA-Z0-9\-\_\/\.\,]+) \s*\t (.+) \s*\t ([0-9\.]+) \t* ([0-9\.]+)*/;

It works all fine, until I get a line with two numbers, in this case the first number (which I want in $3) is in $2 together with the text ((.+)). The 2nd number is in $3 then.
When I change the last /t* to /t both numbers are matched the way I want ($3 and $4) but lines with only one number are not matched at all ($1-$4 undef). What's wrong here? Any hints are welcome.

Thanx, Micha


In reply to Pattern matching with \t by professa

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.