[27796] in Perl-Users-Digest
Perl-Users Digest, Issue: 9160 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 15 14:05:48 2006
Date: Sat, 15 Apr 2006 11:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 15 Apr 2006 Volume: 10 Number: 9160
Today's topics:
regular expressions <sonet.all@msa.hinet.net>
Re: regular expressions <no@email.com>
Re: regular expressions <rvtol+news@isolution.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 15 Apr 2006 22:48:04 +0800
From: "sonet" <sonet.all@msa.hinet.net>
Subject: regular expressions
Message-Id: <e1r13s$hp3$1@netnews.hinet.net>
my $keyword=shift;
$keyword=~s/(&.*?)$//;
print $keyword;
i want to replace the last word like &xyz.
ex:
if $keyword='123123;&12;212222&123' then output 123123;&12;212222
if $keyword='123123;&12;212222&123;' then output 123123;&12;212222&123;
but i alaways got the error result (123123;)
------------------------------
Date: Sat, 15 Apr 2006 16:01:16 +0100
From: Brian Wakem <no@email.com>
Subject: Re: regular expressions
Message-Id: <4acg5tFso8amU1@individual.net>
sonet wrote:
> my $keyword=shift;
> $keyword=~s/(&.*?)$//;
> print $keyword;
>
> i want to replace the last word like &xyz.
>
> ex:
> if $keyword='123123;&12;212222&123' then output 123123;&12;212222
>
> if $keyword='123123;&12;212222&123;' then output 123123;&12;212222&123;
>
> but i alaways got the error result (123123;)
The problem is not described too well. All of the below work, take your
pick according to what it is you are actually trying to do.
$keyword=~s/&\d+$//;
$keyword=~s/&[^;]+$//;
$keyword=~s/&.{3}$//;
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Sat, 15 Apr 2006 17:33:42 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regular expressions
Message-Id: <e1rauu.1f0.1@news.isolution.nl>
sonet schreef:
> my $keyword=shift;
> $keyword=~s/(&.*?)$//;
> print $keyword;
>
> i want to replace the last word like &xyz.
>
> ex:
> if $keyword='123123;&12;212222&123' then output 123123;&12;212222
>
> if $keyword='123123;&12;212222&123;' then output
> 123123;&12;212222&123;
>
> but i alaways got the error result (123123;)
The '?' for minimal matching, doesn't work "from the right".
To remove everything starting at the last '&' up to the end, where the
characters between that last '&' and the end can not be ';'
s/&[^&;]*$//
Since you call it a word, you could also use \w (see perlre)
s/&\w*$//
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9160
***************************************