in reply to Re^2: regex - problem with the loop I believe or maybe the regex itself ?
in thread regex - problem with the loop I believe or maybe the regex itself ?

If I understand correctly, and ignoring the reverse line stuff, what you want to extract is everything between the last occurrence of 'workset((..' up to 'dIonly', and that there are a number of these in each line. If that is the case I would forget about reversing and just split each line on 'dIonly', then find the substring for each segment:
my @a_out; my $line = read_file('data.txt'); if ($line =~ /\bdIonly\b/) { # remove everything after last 'dIonly' $line =~ s/(.*)\bdIonly\b.*?$/$1/; my @segments = split(/\bdIonly\b/,$line); for my $str (@segments) { if ($str =~ /.*(\bworkset\b\(\(.*)/ ) { my $workset = $1; print "workset content: $workset\n\n"; push(@a_out,$workset); } else { print "no workset\n"; } } }
  • Comment on Re^3: regex - problem with the loop I believe or maybe the regex itself ?
  • Download Code