in reply to Parsing text without split

Extract from a regex match: ($flop_a, $t_clk) = $rtpfile[$ln] =~ /Startpoint: (\w+).*?clocked by (\w+)/;

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Parsing text without split
by thundergnat (Deacon) on May 27, 2005 at 22:34 UTC

    That has the same problem as split... It will fail for variables with spaces in them.

    If you can rely on the parenthesis, it would work better as:

    @line_as_list = $rtpfile[$ln] =~ /Startpoint: ([^(]+).*?clocked by ([^ +)]+)\)/;

    Update: Doh! Never mind. I misread the OPs specs.

      I took his meaning to be that the "extra words" were not part of the desired capture. You can capture multiple words with spaces by changing (\w+) to ([\w\s]+).

      Caution: Contents may have been coded under pressure.