in reply to Capture groups

The double tilde ~~ operator is new in perl 5.10, so it won't work in any earlier version.

You can probably use the regex match operator "=~":

if (my @match = $text =~ /([A-Za-z\s]*)([0-9]{1,2})[%])/) { # do stuff here. }

Replies are listed 'Best First'.
Re^2: Capture groups
by wardy3 (Scribe) on Mar 04, 2008 at 23:57 UTC

    The regex above will capture trailing spaces in the $1 variable ([A-Za-z\s]*). It's probably easier to just get rid of them after the match, with $match[0] =~ s/\s+$//; otherwise you'll need a fancier regex :-)

      IMO, it's "easier" to get rid of the trailing spaces (not required by OP, so Joost's correct answer is perfectly serviceable for the specs given) in the original match:

      if ( $string =~ /([A-Za-z]*\s[A-Za-z]*)\s+([0-9]{1,2}[%])/ ) { print $1 . "\n" . $2; # ^ } else ...
Re^2: Capture groups
by doom (Deacon) on Mar 05, 2008 at 02:57 UTC
    The double tilde ~~ operator is new in perl 5.10, so it won't work in any earlier version.

    Damn. For a minute there I thought we'd run into an old awk programmer. But then, awk just uses a single tilde.