in reply to Regex split at number of occurrence

#!/usr/bin/perl # https://perlmonks.org/?node_id=1217751 use strict; use warnings; my $string = "firstname1:::surname1:::middlename1:::firstname2:::surna +me2:::middlename2:::firstname3:::surname3:::middlename3"; my @arr = $string =~ /\w+:::\w+:::\w+/g; use Data::Dumper; print Dumper \@arr;

Replies are listed 'Best First'.
Re^2: Regex split at number of occurrence
by AnomalousMonk (Archbishop) on Jul 02, 2018 at 15:45 UTC

    Of course, that also works with a junky string:

    c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $s = 'junk%%%first1:::sur1:::middle1%%junk%%first2:::sur2:::middle +2%%junk%%first3:::sur3:::middle3%%junk'; ;; my @arr = $s =~ /\w+:::\w+:::\w+/g; dd \@arr; " [ "first1:::sur1:::middle1", "first2:::sur2:::middle2", "first3:::sur3:::middle3", ]
    but the OPer doesn't say if he or she is working with a validated string or not.


    Give a man a fish:  <%-{-{-{-<

Re^2: Regex split at number of occurrence
by Monstar12 (Initiate) on Jul 02, 2018 at 15:21 UTC
    That works thanks!