结构化解析,拆分字符串,该串用正则表达式很麻烦

【问题】

I'm new to Java and to regex in particular I have a CSV file that look something like :

col1,col2,clo3,col4
word1,date1,date2,port1,port2,....some amount of port
word2,date3,date4,
....

What I would like is to iterate over each line (I suppose I’ll do it with simple for loop) and get all ports back. I guess what I need is the fetch every thing after the two dates and look for,(\d+),? and the group that comes back

My question(s) is :

1)Can it be done with one expression? (meaning, without storing the result in a string and then apply another regex)

2) Can I maybe incorporate the iteration over the lines into the regex?

【回答】

       使用Java+正则表达式处理这个实在是很麻烦。把数据的第1-3项各分一列,从第4项开始不管有多少项都分为一列,用SPL只要2句就可以实现这个思路了:

A
1=file("file.txt").import@st()
2=A1.(#1.split@c()).new(~(1):col1,~(2):col2,~(3):col3,~.to(4,).concat@c():col4)

A1:读取文本文件file.txt的内容,不拆分字段,读成单字段串构成的序表。

A2:将A1每一行拆分成4部分,然后创建一个由col1、col2、col3和col4构成的序表,结果如下图:

undefined

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值