in reply to Regex selection based upon position
You can do this with a regex:
my @field = m{ \A (.{20}) \s (.{20}) \s (.{3}) \s (.{3}) \z }msx
But you shouldn’t. Use unpack instead:
my @field = unpack "A20 x A20 x A3 x A3", $_;
Not least because the A pack template will automatically trim the whitespace for you. To achieve this using a regex, you have to jump through hoops:
my @field = m{ \A (.{1,20}?) \s+ (.{1,20}?) \s+ (.{1,3}?) \s+ (.{1,3}? +) \z }msx
Makeshifts last the longest.
|
|---|