my @extract; while (<DATA>) { push @extract,m/\d{8}/g; } print join "\n",@extract; __DATA__ 1,10000021 2,10000023 2,10000035 3,10000043 10000023 10000035 10000043 10000045 10000060 10000043,,zrous 10000045,,sjandw 10000060,,jnbro2 10000063,,eedwa 10000067,,empav 10000021/1 10000023/1 10000035/1 10000043/1 10000045/1 10000060/1 10000021/1,10000021 10000023/1,10000023 10000035/1,10000035 10000112,10002524,10000998,10000071,10000043,10000612,10000018,1000011 +0,10000011,10000013
Outputs:
10000021 10000023 10000035 10000043 10000023 10000035 10000043 10000045 10000060 10000043 10000045 10000060 10000063 10000067 10000021 10000023 10000035 10000043 10000045 10000060 10000021 10000021 10000023 10000023 10000035 10000035 10000112 10002524 10000998 10000071 10000043 10000612 10000018 10000110 10000011 10000013
Of course you could also write that as
my @extracted=map { m/\d{8}/g } <DATA>;
HTH

Yves / DeMerphq
---
Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)


In reply to Re: regular expression to extract 8 digit number from files by demerphq
in thread regular expression to extract 8 digit number from files by Anonymous Monk

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.