in reply to Match, Capture and get position of multiple patterns in the same string
#!/usr/bin/perl use strict; use warnings; use 5.010; my $string = "CATINTHEHATWITHABAT"; my $regex = qr{\wAT}i; my @matches = (); while ($string =~ /($regex)/pg){ my $start = $-[0]; my $end = $+[0]; my $hitpos = "$start-$end"; say "${^MATCH} found at $hitpos"; }
|
|---|