免费注册 查看新帖 |

Chinaunix

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

如何忽略双引号中的分割符 [复制链接]

论坛徽章:
0
1 [报告]
发表于 2011-01-04 17:49 |显示全部楼层
貌似这个问题回答过很多相似的。。

perldoc -q "delimited string"
Found in /usr/lib/perl5/5.8.8/pod/perlfaq4.pod
       How can I split a [character] delimited string except when inside [character]?

       Several modules can handle this sort of pasing---Text::Balanced, Text::CSV, Text::CSV_XS, and
       Text:arseWords, among others.

       Take the example case of trying to split a string that is comma-separated into its different fields. You
       can't use "split(/,/)" because you shouldn't split if the comma is inside quotes.  For example, take a
       data line like this:

           SAR001,"","Cimetrix, Inc","Bob Smith","CAM",N,8,1,0,7,"Error, Core Dumped"

       Due to the restriction of the quotes, this is a fairly complex problem.  Thankfully, we have Jeffrey
       Friedl, author of Mastering Regular Expressions, to handle these for us.  He suggests (assuming your
       string is contained in $text):

            @new = ();
            push(@new, $+) while $text =~ m{
                "([^\"\\]*(?:\\.[^\"\\]*)*)",?  # groups the phrase inside the quotes
              | ([^,]+),?
              | ,
            }gx;
            push(@new, undef) if substr($text,-1,1) eq ',';

       If you want to represent quotation marks inside a quotation-mark-delimited field, escape them with back-
       slashes (eg, "like \"this\"".

       Alternatively, the Text:arseWords module (part of the standard Perl distribution) lets you say:

           use Text:arseWords;
           @new = quotewords(",", 0, $text);

       There's also a Text::CSV (Comma-Separated Values) module on CPAN.

论坛徽章:
0
2 [报告]
发表于 2011-01-04 17:50 |显示全部楼层
禁用掉SMILES之后还有笑脸,郁闷。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP