Re: Newbie backreference question
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Newbie backreference question

From: paulm <paulm@barley.vel.net>
Date: Thu Jun 30 2005 - 23:54:55 CEST

Larry Bates <lbates@syscononline.com> wrote:
> a='test string'
> print a.split()[:-1]
>
> I'm assuming that you want the last space separated word?
>
> Larry Bates
>
>
> paulm wrote:
>> Hi,
>> In perl I can do something like:
>>
>> $a = 'test string';
>> $a =~ /test (\w+)/;
>> $b = $1;
>> print $b . "\n";
>>
>> and my output would be "string".
>>
>> How might this snippet be written in python?
>>
>> Thanks to all...

        No, sorry - my bad. I am looking to assign the
backreference to another variable so it can be treated
seperately. So perhaps:

$a = 'test string two';
$a =~ /test \w{2}([\W\w]+)/;
$b = $1;
print $b . "\n";

producing "ring two".

        I have read the docs and faqs but remain too dense
to comprehend.

Thanks again...
Received on Thu Sep 29 16:40:41 2005