免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: beyondlee1
打印 上一主题 下一主题

正则---请教 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2016-11-16 11:58 |显示全部楼层
  1. my $str1="双面阻焊,油墨型号:ZM-400 WF(指定);颜色:绿色;油墨特性:感光;油墨厚度:厂内管控20+/-5um;导电孔方式:塞孔;无卤素板材,阻焊不可退洗,如要退洗,请提出申请";
复制代码
谢谢,差不多实现了,现在只有一个问题:

如上“指定”两边的括号,是全角模式的,照你现在的脚本只显示“ZM-400 WF",不包括"(指定)"


  1. my $str="单面阻焊:S/S面;油墨型号:PSR-2000 LF03HF(指定);颜色:绿色;油墨特性:感光;油墨厚度:10-25um;无卤素板材不可以退洗,如要退洗请提出申请";
复制代码
这个也是不显示

我看你脚本包含了这种全角(),为何?


谢谢~!

论坛徽章:
0
12 [报告]
发表于 2016-11-16 14:11 |显示全部楼层
本帖最后由 beyondlee1 于 2016-11-16 14:14 编辑
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use utf8;

  5. binmode (STDOUT, ':encoding(utf8)');

  6. sub get_values{
  7.         my $val = shift;
  8.         ($_, $val) = $val =~ m!油墨型号([^a-z]*)((?:\s*[-/a-z0-9]+|\s*[((]指定[))])+)!i;
  9.         $val .= $1 if (/([((]指定[))])/);
  10.         return "$val\n";
  11. }

  12. while (<DATA>){
  13.         print get_values ($_);
  14. }

  15. __DATA__
  16. 双面阻焊,油墨型号:ZM-400 WF(指定);颜色:绿色;油墨特性:感光;油墨厚度:厂内管控20+/-5um;导电孔方式:塞孔;无卤素板材,阻焊不可退洗,如要退洗,请提出申请
  17. 单面阻焊:S/S面;油墨型号:PSR-2000 LF03HF(指定);颜色:绿色;油墨特性:感光;油墨厚度:10-25um;无卤素板材不可以退洗,如要退洗请提出申请
复制代码
我的脚本添加这两句出错:
  1. use utf8;

  2. binmode (STDOUT, ':encoding(utf8)');
复制代码
为何?
错误如下:
  1. Malformed UTF-8 character (unexpected non-continuation byte 0xcd, immediately after start byte 0xd3) at get_mask1.pl line 10.
  2. Malformed UTF-8 character (unexpected non-continuation byte 0xc4, immediately after start byte 0xcd) at get_mask1.pl line 10.
  3. Malformed UTF-8 character (unexpected non-continuation byte 0xcd, immediately after start byte 0xd0) at get_mask1.pl line 10.
  4. Malformed UTF-8 character (unexpected non-continuation byte 0x28, immediately after start byte 0xc5) at get_mask1.pl line 10.
  5. Malformed UTF-8 character (unexpected continuation byte 0xa3, with no preceding start byte) at get_mask1.pl line 10.
  6. Malformed UTF-8 character (unexpected continuation byte 0xa8, with no preceding start byte) at get_mask1.pl line 10.
  7. Malformed UTF-8 character (unexpected continuation byte 0xb6, with no preceding start byte) at get_mask1.pl line 10.
  8. Malformed UTF-8 character (unexpected continuation byte 0xa8, with no preceding start byte) at get_mask1.pl line 10.
  9. Malformed UTF-8 character (unexpected continuation byte 0xa3, with no preceding start byte) at get_mask1.pl line 10.
  10. Malformed UTF-8 character (unexpected continuation byte 0xa9, with no preceding start byte) at get_mask1.pl line 10.
  11. Malformed UTF-8 character (unexpected continuation byte 0xa3, with no preceding start byte) at get_mask1.pl line 11.
  12. Malformed UTF-8 character (unexpected continuation byte 0xa8, with no preceding start byte) at get_mask1.pl line 11.
  13. Malformed UTF-8 character (unexpected continuation byte 0xb6, with no preceding start byte) at get_mask1.pl line 11.
  14. Malformed UTF-8 character (unexpected continuation byte 0xa8, with no preceding start byte) at get_mask1.pl line 11.
  15. Malformed UTF-8 character (unexpected continuation byte 0xa3, with no preceding start byte) at get_mask1.pl line 11.
  16. Malformed UTF-8 character (unexpected continuation byte 0xa9, with no preceding start byte) at get_mask1.pl line 11.
  17. utf8 "\xC3" does not map to Unicode at get_mask1.pl line 15, <DATA> line 1.
  18. Operation "pattern match (m//)" returns its argument for non-Unicode code point 0x189A87 at get_mask1.pl line 10, <DATA> line 1.
  19. Use of uninitialized value $_ in pattern match (m//) at get_mask1.pl line 11, <DATA> line 1.
  20. Use of uninitialized value $val in concatenation (.) or string at get_mask1.pl line 12, <DATA> line 1.
  21. utf8 "\xB5" does not map to Unicode at get_mask1.pl line 16, <DATA> line 2.
  22. Operation "pattern match (m//)" returns its argument for non-Unicode code point 0x189A87 at get_mask1.pl line 10, <DATA> line 2.
  23. Use of uninitialized value $_ in pattern match (m//) at get_mask1.pl line 11, <DATA> line 2.
  24. Use of uninitialized value $val in concatenation (.) or string at get_mask1.pl line 12, <DATA> line 2.
复制代码


论坛徽章:
0
13 [报告]
发表于 2016-11-16 16:38 |显示全部楼层
我用的是editplus,很方便,建议你也用。

另外DOS界面如设置UTF8?

你上传的图片打不开。

学习了,谢谢2

论坛徽章:
0
14 [报告]
发表于 2016-11-17 10:21 |显示全部楼层
将 perl 的标准输出编码与 Windows DOS 控制台的编码保持一致?

不清楚相关设置,能说一下吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP