[sf-perl] Quick question on regular expression and substitution

Adam Morgan Adam.Morgan at safeway.com
Wed Jun 28 10:31:00 PDT 2006


This one works for those situations where you are not sure what will be
between the occurences of the character you are trying to replace. It is
only any good for single character replaces though as it is below.
 
$string =~ s/^([^?]*\?[^?]*\?[^?]*)(\?)(.*)$/\1to_date(?, 'YYYY-MM-DD
HH24:MI:SS')\3/;

________________________________

From: sanfrancisco-pm-bounces+adam.morgan=safeway.com at pm.org
[mailto:sanfrancisco-pm-bounces+adam.morgan=safeway.com at pm.org] On
Behalf Of Loo, Peter # PHX
Sent: Wednesday, June 28, 2006 9:19 AM
To: San Francisco Perl Mongers User Group
Subject: [sf-perl] Quick question on regular expression and substitution


Hi All,
 
Would some one know of a one liner that would replace the third
occurrence of a substring within a string?  For example:
 
$string = "?, ?, ?, ?";
 
I want to replace the third occurrence of "?" with "to_date(?,
'YYYY-MM-DD HH24:MI:SS')".
 
Thanks in advance.
 
Peter
 

"MMS <safeway.com>" made the following annotations.
------------------------------------------------------------------------------
Warning: 
All e-mail sent to this address will be received by the Safeway corporate e-mail system, and is subject to archival and review by someone other than the recipient.  This e-mail may contain information proprietary to Safeway and is intended only for the use of the intended recipient(s).  If the reader of this message is not the intended recipient(s), you are notified that you have received this message in error and that any review, dissemination, distribution or copying of this message is strictly prohibited.  If you have received this message in error, please notify the sender immediately. 
  
==============================================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20060628/334ab4d8/attachment.html 


More information about the SanFrancisco-pm mailing list