in reply to Re: newbie to regex: all matches
in thread newbie to regex: all matches

I know all about using that module but I want to do it myself since I'll get experience using regexes in this way. It's not much of a script that will ever do anything, it's just for playing and testing. So if it doesn't always match id the page changes, it doesn't affect anything. I just want to learn how to match every occurence into an array.

Thanks.

Replies are listed 'Best First'.
Re^3: newbie to regex: all matches
by GrandFather (Saint) on Mar 10, 2006 at 01:03 UTC
    use warnings; use strict; my $str = do {local $/; <DATA>}; my @matches = $str =~ /(\w+):(.*)/g; print "@matches\n"; __DATA__ 1: one 2: two 3: three

    Prints:

    1 one 2 two 3 three

    DWIM is Perl's answer to Gödel