in reply to A regex I cant get my head around

Looks like it is trying to parse key value pairs that are delimited by ampersands ... maybe GET parameters? [^&]+ matches anything that is not an ampersand and the parens around it capture the match into $1. \& matches a mandatory ampersand. Here is some test code to see what is matched and what is not:
use strict; for (qw(foo foo& &foo foo&bar)) { /([^&]+)\&/; print "$_ - $1\n"; }
Seems to me that the variable $key in your code should be renamed $value, because that is what it is really trying to capture. Also, depending upon what the goal really is for this code, i might suggest using a CPAN module such as URI to pull out the key/value pairs:
use strict; use URI; my $uri = URI->new(); $uri->query('THING=super%20hero&KEY=foobar'); my %hash = $uri->query_form(); print $hash{KEY}, "\n";
Notice that KEY is last, and it's value is not succeeded by an ampersand.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: A regex I cant get my head around
by Anonymous Monk on Aug 03, 2002 at 21:08 UTC
    Thanks cLive and jeffa, but it has nothing to do with GET params. If
    $text->as_string() = "startKEY=jdjhjfg8y4uh449845&finish"
    what value ids assigned to $key?
      Why not find out for yourself? All you need to do is change your code to something like:
      my $as_string = 'startKEY=jdjhjfg8y4uh449845&finish'; $as_string =~ /KEY=([^&]+)\&/; print $1, "\n";
      Regardless of whether or not this has to do with GET params, you can still use URI to parse any key=value pairs that are delimited by ampersands:
      use strict; use URI; my $uri = URI->new(); $uri->query('startKEY=jdjhjfg8y4uh449845&finish'); my %pair = $uri->query_form(); print $pair{startKEY}, "\n";

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)