in reply to Re: Re: Replacing parts of a string
in thread Replacing parts of a string
You can capture into $1, $2, $etc using parens around (what you want) in a regex. If there are multiple parens then you get the first capture in $1, next in $2, etc
$str = 'http://somesite.com/cgi-bin/calendar.pl?some=qstring'; # the typical perlish idiom looks like this # we are capturing $1 and $2 and assigning them to vars # all in one line (note this uses m//) my ( $site, $q_string ) = $str =~ m/^([^\?]+)\?(.*)$/; print "site: $site\nq string: $q_string\n"; # simple way, just modifying the s/// we had $str =~ s/^([^\?]+)\?//; my $capture = $1; print $capture; # $str now contains q string
Details see perlre
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|