> Hi,
> Can someone help me with the syntax of deleting the last word of text
string.
> i.e. $string = 'my abc 123'
> Like to have only 'my abc'
>
> Thanks,
> David
#!/usr/bin/perl
$string = 'some string';
$string =~ s/(?<=\s)(.*?)$//g;
print "String = $string\n";
HTH
-Erich-
_
On Wed, 16 Feb 2005, Erich Beyrent wrote:
> > Can someone help me with the syntax of deleting the last word of text
> string.
> > i.e. $string = 'my abc 123'
> > Like to have only 'my abc'
>
> #!/usr/bin/perl
>
> $string = 'some string';
> $string =~ s/(?<=\s)(.*?)$//g;
>
> print "String = $st
You can do this a few ways. Here are two:
my ($way_1) = $string =~ /(\w+\s{1,}\w+)\s{1,}\w+$/;
my ($way_2) = join(" ",@_[0,1] = split(/ +/,$string));
print "way_1 = $way_1\n";
print "way_2 = $way_2\n";
Out of curiosity, I benchmarked these and the regex is faster than the array
slice. Lucky for
Hsu, David [HD], on Wednesday, February 16, 2005 at 10:26 (-0500)
thoughtfully wrote the following:
HD> Can someone help me with the syntax of deleting the last word of text
HD> string.
HD> i.e. $string = 'my abc 123'
HD> Like to have only 'my abc'
my $string = 'my abc 123 f ';
$string =~ s/(.*)\
Hello David,
Wednesday, February 16, 2005, 5:26:22 PM, Вы написали:
HD> Hi,
HD> Can someone help me with the syntax of deleting the last word of text
HD> string.
HD> i.e. $string = 'my abc 123'
HD> Like to have only 'my abc'
use strict;
my $string = 'my abc 123';
$_ = $string;
my @string = spl
-Original Message-
> Can someone help me with the syntax of deleting the last word of text
string.
> i.e. $string = 'my abc 123'
> Like to have only 'my abc'
David,
Quick and easy:
$string = 'my abc 123';
$string =~ s/\s+\S+$//;
This assumes that you are replacing one or more whitespac
Try '^[\[\]a-zA-Z0-9-_. ]+$'
Dirk Bremer - Senior Systems Engineer - ESS/AMS - NISC Lake St. Louis MO
- USA Central Time Zone
636-755-2652 fax 636-755-2503
[EMAIL PROTECTED]
www.nisc.coop
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf
Scott wrote:
How can I incorporate the possibility of having a [ or ] in the user
input?
/^[a-zA-Z0-9-_. \[\]]+$/
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysub
-Original Message-From:
[EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]On Behalf Of
Scott PurcellSent: Thursday, March 23, 2006 12:05To:
Perl-Win32-Users@listserv.ActiveState.comSubject: Reg _expression_
Help
Hello,
I have a regular _expression_ in
which I a
Scott Purcell wrote, on Thursday, March 23, 2006 3:05
PM
: '^[a-zA-Z0-9-_.
]+$'
The others helped you get [] in
there. But hyphen (dash) has to be first, or it looks like a range operator. So
try:
^[-a-zA-Z0-9_.
\[\]]+$
Good
luck,
Joe
___
Hi, I think you should escape that period and dash as well.'^[a-zA-Z0-9-_. \[\]]+$''^[a-zA-Z0-9\-_\. \[\]]+$'or may be simpler:'^[\w\d_\-\. \[\]]+$'
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://list
11 matches
Mail list logo