You can set pos of the string to continue matching, and then capture the digits to the left and right of the continuation point (\G):

#!/usr/bin/perl use 5.020; use experimental 'signatures'; use Test::More; sub digits( $S, $pos ) { pos($S) = $pos; return ($S =~ m/\b(\d*\G\d*)\b/c) ? $1 : undef; } is digits( 'Hello World 123456 !!! 789 ...', 14 ), '123456', "In middl +e"; is digits( '12345 World 123456 !!! 789 ...', 14 ), '123456', "No digit +s before"; is digits( '12345 World 123456 !!! 789 ...', 17 ), '123456', "At end"; is digits( '12345 World 123456 !!! 789 ...', 12 ), '123456', "At start +"; done_testing;

In reply to Re: How to capture backwards using regex? by Corion
in thread How to capture backwards using regex? by harangzsolt33

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.