in reply to Extract firstname and lastname from variable
The problem with your regexes is that you use the start of string anchor ^ in the middle of the string where it can't possibly match. In fact split is likely to be a better tool for this exercise. Consider:
use strict; use warnings; for my $name (qw'JoeZZZJones JoeZZZJosephZZZJones Bobbie') { my @parts = split 'ZZZ', $name; print "Name: $name\n"; print "Name part $_: $parts[$_ - 1]\n" for 1 .. @parts; print "\n"; }
Prints:
Name: JoeZZZJones Name part 1: Joe Name part 2: Jones Name: JoeZZZJosephZZZJones Name part 1: Joe Name part 2: Joseph Name part 3: Jones Name: Bobbie Name part 1: Bobbie
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extract firstname and lastname from variable
by colwellj (Monk) on Mar 01, 2010 at 02:41 UTC | |
|
Re^2: Extract firstname and lastname from variable
by llancet (Friar) on Mar 01, 2010 at 03:04 UTC |