in reply to Re: Replacing parts of a string
in thread Replacing parts of a string

silly question, however I know it will take you seconds to answer and me hours to find, but, how do you get the bit which you strippped when you did:

$str =~ s/^[^\?]+\?//;

i.e. I am looking for 'calendarview.pl'

Thank you.

Replies are listed 'Best First'.
Re: Re: Re: Replacing parts of a string
by tachyon (Chancellor) on Apr 16, 2003 at 03:15 UTC

    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