in reply to newbie to regex: all matches

Don't use regexen for parsing HTML - it leads to an unhappy life! Instead use modules like HTML::TreeBuilder. Look for the look_down method of element.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: newbie to regex: all matches
by Anonymous Monk on Mar 10, 2006 at 00:36 UTC
    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.

      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