Re: Request for regex: Strip last dash in a record

2005-02-15 Thread Ken Simon
[EMAIL PROTECTED] wrote:
If you just want to remove the last occuring '-' character, then the
following would work.
s/(.*)-(.*)/$1$2/;

Well, huh.  That does work.  Though it reminds me only of how little I
understand why.
Thanks,  you've made it look easy.
His regex works because perl uses greedy regular expression matching.  This 
means that perl matches the longest string possible when you use the first .*. 
Which means the first .* ($1) matches all the -'s except for the last one.

A bit less confusing regex, IMO, would be
s/(.*)-([^-])/$1$2/;
Which defines the second backreference to be specifially characters that aren't 
-'s.
--
Ken Simon
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Request for regex: Strip last dash in a record

2005-02-15 Thread Peter_Farrar

>
>If you just want to remove the last occuring '-' character, then the
>following would work.
>
>s/(.*)-(.*)/$1$2/;

Well, huh.  That does work.  Though it reminds me only of how little I
understand why.

Thanks,  you've made it look easy.



** CONFIDENTIALITY NOTICE **
NOTICE:  This e-mail message and all attachments transmitted with it may 
contain legally privileged and confidential information intended solely for the 
use of the addressee.  If the reader of this message is not the intended 
recipient, you are hereby notified that any reading,
dissemination, distribution, copying, or other use of this message or its
attachments is strictly prohibited.  If you have received this message in
error, please notify the sender immediately and delete this message from your 
system.  Thank you..



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Request for regex: Strip last dash in a record

2005-02-15 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
Hi All,
Hello,
The code below does what I want to do, but it takes 3 lines and a temporary
array (yuck).
It does?  Could you please explain what exactly you want to do?  Just going 
by
your subject line, this will work (assuming $_ contains the data.)
s/(.*)-/$1/;
I can't come up with a one line regex substitution.  Anyone
got one?
my $tmp = reverse split //, $_;
$tmp =~ s/-//;
$_ = reverse split //, $tmp;
There is no temporary array there but there is a list created by split() 
however reverse() works just fine with scalars so:

my $tmp = reverse split //, $_;
And:
my $tmp = reverse $_;
Do the same thing but in the second one reverse does not have a list to 
concatenate.  In some cases reversing a string to do a substitution is more 
efficient but that depends on your data.

And of course (TMTOWTDI) you can accomplish the same thing without using 
regular expressions:

# note: using the global variable $a as a temp
substr $_, $a, 1, '' if ( $a = rindex $_, '-' ) >= 0;

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Request for regex: Strip last dash in a record

2005-02-15 Thread Wagner, David --- Senior Programmer Analyst --- WGO
[EMAIL PROTECTED] wrote:
>> [EMAIL PROTECTED] wrote:
>> 
>>> Hi All,
>>> 
>>> The code below does what I want to do, but it takes 3 lines and a
>>> temporary array (yuck).  I can't come up with a one line regex
>>> substitution. Anyone got one? 
>>> 
>>> my $tmp = reverse split //, $_;
>>> $tmp =~ s/-//;
>>> $_ = reverse split //, $tmp;
>> 
>> can you post a sample string which you want to substitute..
> 
> sure.
> 
> Example record:
> 0-0-0-EXAMPLE-00-621
> 
If this is the format then,
s/\-(\d+)$/$1/;
This assumes numerica as last portion before the end of the variable.

Wags ;)

> Will become:
> 0-0-0-EXAMPLE-00621
> 
> - Peter
> 
> 
> 
> 
> 
> ** CONFIDENTIALITY NOTICE **
> NOTICE:  This e-mail message and all attachments transmitted with it
> may contain legally privileged and confidential information intended
> solely for the use of the addressee.  If the reader of this message
> is not the intended recipient, you are hereby notified that any
> reading, dissemination, distribution, copying, or other use of this
> message or its
> attachments is strictly prohibited.  If you have received this
> message in 
> error, please notify the sender immediately and delete this message
> from your system.  Thank you.. 



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Request for regex: Strip last dash in a record

2005-02-15 Thread Ankur Gupta
[EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] wrote:
   

Hi All,
The code below does what I want to do, but it takes 3 lines and a
 

temporary
 

array (yuck).  I can't come up with a one line regex substitution.
 

Anyone
 

got one?
my $tmp = reverse split //, $_;
$tmp =~ s/-//;
$_ = reverse split //, $tmp;
 

can you post a sample string which you want to substitute..
   

sure.
Example record:
0-0-0-EXAMPLE-00-621
Will become:
0-0-0-EXAMPLE-00621
If you just want to remove the last occuring '-' character, then the 
following would work.

s/(.*)-(.*)/$1$2/;


Re: Request for regex: Strip last dash in a record

2005-02-15 Thread Peter_Farrar

>[EMAIL PROTECTED] wrote:
>
>>Hi All,
>>
>>The code below does what I want to do, but it takes 3 lines and a
temporary
>>array (yuck).  I can't come up with a one line regex substitution.
Anyone
>>got one?
>>
>>my $tmp = reverse split //, $_;
>>$tmp =~ s/-//;
>>$_ = reverse split //, $tmp;
>
>can you post a sample string which you want to substitute..

sure.

Example record:
0-0-0-EXAMPLE-00-621

Will become:
0-0-0-EXAMPLE-00621

- Peter





** CONFIDENTIALITY NOTICE **
NOTICE:  This e-mail message and all attachments transmitted with it may 
contain legally privileged and confidential information intended solely for the 
use of the addressee.  If the reader of this message is not the intended 
recipient, you are hereby notified that any reading,
dissemination, distribution, copying, or other use of this message or its
attachments is strictly prohibited.  If you have received this message in
error, please notify the sender immediately and delete this message from your 
system.  Thank you..



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]