im not really good in regex...but this is something that is making me pull my hair. Basically, im trying to read from a result file that is something like this :
Title Percent2 Percent3 test1.cpp 0.00% of 21 0.00% of 16 test2.c None 16.53% of 484 test3.h 0.00% of 138 None
I'm trying to extract Title, Percent2, and Percent3 into individual variables. Percent2 and Percent3 can be percentage or 'None'. Here's what I did :
#!perl local @match; open(FILE_EXPECTED_RESULT, "< gcov_report.txt"); while(<FILE_EXPECTED_RESULT>) { chomp($_); if ($_ ne "") { print $_ . "\n"; (@match) =($_ =~ /((.*\.c\s)|(.*\.h\s)|(.*\.cpp\s))|(\s+(. +*)\%\s+(of)\s+\d+\s)|(\bNone\b)/g); print "title : ".$match[0]."\n"; print "percent2 : ".$match[1]."\n"; print "percent3 : ".$match[2]."\n"; } } close (FILE_EXPECTED_RESULT);
it is returning weird stuff :
Title Percent2 Percent3 title : percent2 : percent3 : test1.cpp 0.00% of 21 0.00% of 16 title : test1.cpp percent2 : percent3 : test2.c None 16.53% of 484 title : test2.c percent2 : test2.c percent3 : test3.h 0.00% of 138 None title : test3.h percent2 : percent3 : test3.h

In reply to how to extract string by possible groupings? by adrive

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.