[sf-perl] Quick question on regular expression and substitution
David Fetter
david at fetter.org
Wed Jun 28 10:04:39 PDT 2006
On Wed, Jun 28, 2006 at 10:01:28AM -0700, David Fetter wrote:
> On Wed, Jun 28, 2006 at 09:19:15AM -0700, Loo, Peter # PHX wrote:
> > 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
>
> Peter,
>
> Given the high wackiness of regexes, I'd do something like:
>
> $old = '(?, ?, ?, ?)'; # So you're covered on just exactly which clause.
> $new = q{?, ?, to_date(?, 'YYYY-MM-DD HH24:MI:SS'), ?'};
Oops. That should read:
$new = q{(?, ?, to_date(?, 'YYYY-MM-DD HH24:MI:SS'), ?)};
Cheers,
D
--
David Fetter <david at fetter.org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter
Remember to vote!
More information about the SanFrancisco-pm
mailing list