2009年11月21日星期六

[PerlChina] Re: 请教如何把日期中的中文规换为-号?

use Encode qw /_utf8_on/;

$date = "2009年1月1日";
$date =~ s/\p{Han}/-/gs;

print $date


不过这个问题似乎应该提取数字更靠谱, 呵呵

2009/11/20 Alex <xjdengz@gmail.com>

On Fri, Nov 20, 2009 at 05:03:41PM +0800, x2x4 wrote:
>2009年1月1日  oops
>

$str = "2009年1月1日";

$str =~ s/(\d{4}).+?(\d).+?(\d).*/$1-$2-$3/;

Put the Chinese character set to wildcard, it looks like working well.

>2009/11/11 Tiger Peng <tigerpeng2001@gmail.com>:
>> $datetime=~s{(\d\d\d\d)(年)(\d\d)(月)(\d\d)(日)}
>>                     {$1-$2-$3}gxms;
>>
>> 或
>>
>> $datetime=~s{(\d\d\d\d)(\D)(\d\d)(\D)(\d\d)(\D)}
>>                     {$1-$2-$3}gxms;
>>
>> 2009/11/10 imxae <imx365ster@gmail.com>:
>>> 把数字提出来,这是个想法,研究中
>>>
>>> >
>>>
>>
>> >
>>
>
>>




--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛"PerlChina Mongers 讨论组"论坛。
 要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
 要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛

-~----------~----~----~----~------~----~------~--~---

没有评论: