gilthoniel has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'm trying to write a script that will return the substring of a string that starts and ends with specific characters
ex:
string: asdfgfhjkl
parameters: start with f and end with j
return: fgfhj, fhj
I've tried regex but it will only return the full string if it contains an f followed by a j at some point.
Thanks
Comment on Return string that starts and ends with specific characters
#!/usr/bin/perl
# http://perlmonks.org/?node_id=1164776
use strict;
use warnings;
my @answer;
'asdfgfhjkl' =~ /f.*j(?{push @answer, $&})^/;
print "$_\n" for @answer;