/([0-8])[a-z](??{ $1 + 1 })/
See perlre for details.
Updated: Simplified, don't use named capture groups.
#!/usr/bin/perl use warnings; use strict; use Test2::V0 '-no_srand' => 1; my @cases = ( ['13s4', '3s4'], ['3s44', '3s4'], ['0a1', '0a1'], ['0a2', undef], ['9y10', undef] ); for my $case (@cases) { my ($line, $expected) = @$case; my $result; $result = $& if $line =~ /([0-8])[a-z](??{ $1 + 1 })/; is $result, $expected, $line; } done_testing;
In reply to Re: arithmetic in a regex ?
by choroba
in thread arithmetic in a regex ?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |