亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 5452 | 回復(fù): 5
打印 上一主題 下一主題

Perl正則表達(dá)式處理指定漢字的問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-03-20 10:37 |只看該作者 |倒序?yàn)g覽
有段文字:

  例如:  外層短邊拉伸:3MIL,長邊收縮:5MIL。

現(xiàn)在我想處理的結(jié)果是:如果自動根據(jù)文字描述提取相應(yīng)的參數(shù):

如果出現(xiàn):“短邊” 關(guān)鍵字就輸出為 X,“長邊”關(guān)鍵字就輸出為  Y.  "拉伸“ 為: +  ,”收縮“為:-  

那么上面的文字,處理結(jié)果應(yīng)為:   X:3MIL,Y:-5MIL

但是在程序做正則表達(dá)式處理時,直接在表達(dá)式里面過濾指定漢字,程序過濾不了。請問高手,這個正則表達(dá)式應(yīng)該怎么書寫。謝謝!

論壇徽章:
78
雙子座
日期:2013-10-15 08:50:09天秤座
日期:2013-10-16 18:02:08白羊座
日期:2013-10-18 13:35:33天蝎座
日期:2013-10-18 13:37:06獅子座
日期:2013-10-18 13:40:31雙子座
日期:2013-10-22 13:58:42戌狗
日期:2013-10-22 18:50:04CU十二周年紀(jì)念徽章
日期:2013-10-24 15:41:34巨蟹座
日期:2013-10-24 17:14:56處女座
日期:2013-10-24 17:15:30雙子座
日期:2013-10-25 13:49:39午馬
日期:2013-10-28 15:02:15
2 [報(bào)告]
發(fā)表于 2015-03-20 12:17 |只看該作者
正常匹配if處理不行嗎?

論壇徽章:
3
CU十二周年紀(jì)念徽章
日期:2013-10-24 15:41:34子鼠
日期:2013-12-14 14:57:19射手座
日期:2014-04-25 21:23:23
3 [報(bào)告]
發(fā)表于 2015-03-20 15:21 |只看該作者
本帖最后由 mcshell 于 2015-03-20 15:22 編輯
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. binmode( STDIN,  ':encoding(utf8)' );
  6. binmode( STDOUT, ':encoding(utf8)' );   
  7. binmode( STDERR, ':encoding(utf8)' );   
  8.   my $h = {
  9. '短邊' => 'X',
  10. '長邊' => 'Y',
  11. '拉伸' => '+',
  12. '收縮' => '-',
  13. ':' =>':'
  14. };
  15. my $str = '外層短邊拉伸:3MIL,長邊收縮:5MIL';
  16. for (keys %$h){
  17.         $str =~ s/$_/$h->{$_}/eg;
  18. }
  19.         $str=~ s/(.):/:$1/g;
  20.         $str=~ s/[\x{4e00}-\x{9fa5}]+//g;
  21.         print $str;
復(fù)制代碼

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2015-03-22 22:41 |只看該作者
回復(fù) 3# mcshell


    你好,您的程序,我運(yùn)行了。提示有錯誤信息。不知道是什么情況,請幫忙看下,謝謝!

C:\Perl\bin>perl aa.pl
Malformed UTF-8 character (unexpected non-continuation byte 0xec, immediately af
ter start byte 0xc9) in regexp compilation at aa.pl line 17.
Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) in regexp comp
ilation at aa.pl line 17.
Malformed UTF-8 character (unexpected non-continuation byte 0xec, immediately af
ter start byte 0xc9) in regexp compilation at aa.pl line 17.
Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) in regexp comp
ilation at aa.pl line 17.
Malformed UTF-8 character (unexpected non-continuation byte 0xd5, immediately af
ter start byte 0xca) in regexp compilation at aa.pl line 17.
Malformed UTF-8 character (unexpected non-continuation byte 0xcb, immediately af
ter start byte 0xd5) in regexp compilation at aa.pl line 17.
Malformed UTF-8 character (unexpected non-continuation byte 0xf5, immediately af
ter start byte 0xcb) in regexp compilation at aa.pl line 17.
Malformed UTF-8 character (1 byte, need 4, after start byte 0xf5) in regexp comp
ilation at aa.pl line 17.
Malformed UTF-8 character (unexpected non-continuation byte 0xd5, immediately af
ter start byte 0xca) in regexp compilation at aa.pl line 17.
Malformed UTF-8 character (unexpected non-continuation byte 0xcb, immediately af
ter start byte 0xd5) in regexp compilation at aa.pl line 17.
Malformed UTF-8 character (unexpected non-continuation byte 0xf5, immediately af
ter start byte 0xcb) in regexp compilation at aa.pl line 17.
Malformed UTF-8 character (1 byte, need 4, after start byte 0xf5) in regexp comp
ilation at aa.pl line 17.
Malformed UTF-8 character (1 byte, need 2, after start byte 0xdf) in regexp comp
ilation at aa.pl line 17.
Malformed UTF-8 character (1 byte, need 2, after start byte 0xdf) in regexp comp
ilation at aa.pl line 17.
Malformed UTF-8 character (1 byte, need 2, after start byte 0xdf) in regexp comp
ilation at aa.pl line 17.
Malformed UTF-8 character (1 byte, need 2, after start byte 0xdf) in regexp comp
ilation at aa.pl line 17.
Malformed UTF-8 character (fatal) at aa.pl line 20.

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2015-03-22 22:42 |只看該作者
回復(fù) 4# h97252


    Linux平臺和WINDOWS平臺我都測試了,都是提示這樣的錯誤。

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2015-03-25 11:30 |只看該作者
回復(fù) 3# mcshell


        程序沒問題,是我沒處理好。現(xiàn)在已經(jīng)可以運(yùn)行OK。非常感謝MCSHELL的無私幫助!
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP