in reply to Stumped by regex
Update: You can replace everything in the foreach scope with: -use strict; my @names = ( 'Joe John Smith', 'David George', 'Emma Harry Sally Martin', ); foreach (@names) { my @w = split /\s/, (/\s+(\w[\w ]{0,18}\w)\s*$/)[0]; shift @w while @w > 2; print "@w\n"; }
(/\s+(\w[\w ]{0,18}\w)\s*$/)[0] =~ /(\w+\s?\w+)$/g;
|
|---|