Next Regular Expression Mastery 69

Repeated Matching: /g

        "Madagascar" =~ m/a./g;     # returns ('ad', 'ag', 'as', 'ar')
        "12-345:6 78" =~ m/\d+/g;   # returns ('12', '345', '6', '78')
        @substrings = "abcdefghijklmnopqrstuvwxyz" =~ /.{1,5}/g;
        # Yields ('abcde', 'fghij, 'klmno', 'pqrst', 'uvwxy', 'z')


Next Copyright © 2002 M. J. Dominus