in reply to regular expression to extract 8 digit number from files

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)

Replies are listed 'Best First'.
Re: Re: regular expression to extract 8 digit number from files
by Anonymous Monk on Aug 16, 2002 at 11:47 UTC
    Thanks very much - as usual I was over-complicating things. Col
Re: Re: regular expression to extract 8 digit number from files
by Anonymous Monk on Aug 16, 2002 at 12:03 UTC
    How would I get to pick numbers ranging from 5 - 8 digits in length, I've tried using m/\d{5,8}/g but that doesn't work. TIA