in reply to Return string that starts and ends with specific characters

#!/usr/bin/perl # http://perlmonks.org/?node_id=1164776 use strict; use warnings; print "$1\n" while 'asdfgfhjkl' =~ /(?=(f.*j))/g

Replies are listed 'Best First'.
Re^2: Return string that starts and ends with specific characters
by Eily (Monsignor) on Jun 02, 2016 at 16:56 UTC

    The previous one works not only with multiple 'f's but also with multiple 'j's, this one will always match up to the rightmost 'j'.

      Yep. I was not sure what his actual requirements were, so I showed both.

      Thanks this is great! How would I get it to print only to the leftmost j?
        to clarify, I want it to start at any available "f", but end at only the first "j" after that "f". Thanks