Okay, as we chatted, the data is actually from satellite pictures, so it comes like this, a digit string. It is the analyzer's responsibility to mining and dig out certain textures/patterns and process/use the data, one of its application is to find and locate natural resources.

It is impossible for the regexp to mess up 12.24 with 24.4812367, or mess 12.242 with 4.4812367. If you test the regexp, you will see it does well, and matches 12.24 with 24.48 as specified by function e1.

Even better, if you look at the first two digits, although the second digit doubles the first digit, it will not mess up 1 with 2, as I am using greedy match, it will try find the longest possible substring that satisfies e1, so it will dig until find the pair of 12.24 and 24.48. This serves the purpose to reduce background noises.

I changed e2 a bit, so it demos the purpose more clearly:
sub e1 { shift() * 2; } sub e2 { "(".shift().",".shift().")"; } $a = "12.2424.4812367"; $a =~ s/((?:\d+(?:\.\d+)?))((??{e1($+)}))/e2($1, $2)/ge; print $a;
The output would be (12.24,24.48)(1,2)(3,6)7

In reply to Re: Re: Is this enough good, or can be improved? by pg
in thread Is this enough good, or can be improved? by pg

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.