in reply to How to capture backwards using regex?
my ($after) = $str =~ /^.{$pos}(\d*)/; my ($before) = length $after ? reverse($str) =~ /(?=(\d*))(?=.{$pos}$)/ : ""; my $match = reverse($before) . $after;
Update: I wasn't able to use Grimy's trick to solve the problem. Anyone? I tried hundreds of variations of the following:
$str =~ /^.{$pos} ( (?<= (?= \D | ^ | (?1) (\d\d) ) ) ) (\d+) /x;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to capture backwards using regex?
by jo37 (Curate) on Nov 11, 2024 at 15:46 UTC | |
Re^2: How to capture backwards using regex?
by LanX (Saint) on Nov 11, 2024 at 19:40 UTC | |
by choroba (Cardinal) on Nov 11, 2024 at 19:53 UTC | |
by LanX (Saint) on Nov 11, 2024 at 21:51 UTC |