in reply to Re: 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 ?

thanks that is a good start. So could you please tell me how I can extend the content that it returns, right now it firstly does not return the whole content of workset, but only a subpart secondly even if I apply global, it does only do it for one part, but there are several dIonly in the string, hence I would want to extract a number of these worksets.
  • Comment on Re^2: regex - problem with the loop I believe or maybe the regex itself ?

Replies are listed 'Best First'.
Re^3: regex - problem with the loop I believe or maybe the regex itself ?
by tangent (Parson) on Feb 13, 2014 at 03:52 UTC
    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"; } } }