in reply to Regex help

Try your regex like this:

@data = <DATA>; @extracted = (); foreach(@data){ while ($_ =~ s/(foo\d+)//) { push @extracted, $1; } } print join( ':', @extracted ), "\n" ; __DATA__ foo1 foo2 foo3 foo4 foo5 foo6 foo7 foo8 foo9

Update:This does the same thing:

@data = <DATA>; my @extracted = grep { /foo\d+/ } map { split } @data ; print join( ':', @extracted ), "\n" ; __DATA__ foo1 foo2 foo3 foo4 foo5 zoot6 foo6 foo7 foo8 bar1 foo9

_______________
D a m n D i r t y A p e
Home Node | Email

Replies are listed 'Best First'.
Re: Re: Regex help
by japhy (Canon) on Jul 08, 2002 at 19:24 UTC
    You are making assumptions about the poster's data. Also, there's no need to use a substitution when a simple
    while (/(foo\d+)/g) { push @ext, $1; }
    would work.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;