in reply to Regarding Regular Expressions

if( $string =~ /e/g ) { my $start_pos = pos($string) - 1; while ($string =~ /fg/g) { print substr($string, $start_pos, pos($string) - $start_pos) , " +\n"; } } # outputs efg efghijklfg efghijklfghijklabcdefg

Or if you want to catch 'e.*gh' for every 'e':

$string = 'abcdefghijklfghijklabcdefg'; while( $string =~ /e/g ) { my $start_pos = pos($string) - 1; while ($string =~ /fg/g) { print substr($string, $start_pos, pos($string) - $start_pos) , " +\n"; } pos($string) = $start_pos + 1; } # outputs efg efghijklfg efghijklfghijklabcdefg efg

see perldoc perlretut, perldoc -f pos

Replies are listed 'Best First'.
Re^2: Regarding Regular Expressions
by Sameet (Beadle) on Aug 17, 2004 at 11:40 UTC
    hi ccn,
    Thanks a ton. I got the solution.

    Regards
    Sameet