栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Java用逗号分隔引号外

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java用逗号分隔引号外

你可以尝试以下正则表达式:

str.split(",(?=(?:[^"]*"[^"]*")*[^"]*$)");

这将分割字符串,,后跟偶数双引号。换句话说,它用双引号引起来的逗号分隔。如果你在字符串中使用了引号,则此方法将起作用。

说明:

,// Split on comma(?=         // Followed by   (?:      // Start a non-capture group     [^"]*  // 0 or more non-quote characters     "      // 1 quote     [^"]*  // 0 or more non-quote characters     "      // 1 quote   )*       // 0 or more repetition of non-capture group (multiple of 2 quotes will be even)   [^"]*    // Finally 0 or more non-quotes   $        // Till the end  (This is necessary, else every comma will satisfy the condition))

你甚至可以在代码中使用

(?x)
正则表达式使用修饰符来键入此类内容。修饰符会忽略你的正则表达式中的任何空格,因此更容易读取分成多行的正则表达式,如下所示:

String[] arr = str.split("(?x)   " +",          " +   // Split on comma          "(?=        " +   // Followed by          "  (?:      " +   // Start a non-capture group          "    [^"]* " +   // 0 or more non-quote characters          "    "     " +   // 1 quote          "    [^"]* " +   // 0 or more non-quote characters          "    "     " +   // 1 quote          "  )*       " +   // 0 or more repetition of non-capture group (multiple of 2 quotes will be even)          "  [^"]*   " +   // Finally 0 or more non-quotes          "  $        " +   // Till the end  (This is necessary, else every comma will satisfy the condition)          ")          "     // End look-ahead   );


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/431902.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号