Java String.split()在逗号后面跟着非空格 [英] Java String.split() on comma followed by non-whitespace

查看:1012
本文介绍了Java String.split()在逗号后面跟着非空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解析一个数据集,该数据集恼人地决定用逗号分隔TSV中的项目(PharmaGKB路径,我正在看你),但在每个逻辑元素中都允许使用逗号。

I'm parsing a dataset which annoyingly decided to comma-delimit items in a TSV (PharmaGKB pathways, I'm looking at you), but allow commas in each logical element.

基本上,逗号后跟空格表示没有分隔符,而逗号后跟字符表示新元素。

Basically, comma-followed-by-space means no delimit, while comma followed by character means new element.


这是一个元素,两个元素,三个元素

"This is one, element,two element, three element"

应该是:


  • 这是一个元素

  • 两个元素

  • 三元素

我有正则表达式 a.split(,\\ S +); ,它分裂正常它会在每次拆分后删除第一个字符。

I have the regex a.split(",\\S+");, which splits fine but it removes the first character after every split.


  • 这是一个元素

  • wo element

  • hree element

正则表达式就像去看牙医一样非常感谢帮助。

Regex is like going to the dentist for me, help is much appreciated.

推荐答案

积极的向前看:

a.split(",(?=\\S)");

这篇关于Java String.split()在逗号后面跟着非空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆