[英]A Regex for Group Matching in Java
I have a row of data that is split by tabs. 我有一排数据,按标签分开。 I want to do a counted matching: first three are in group 1, second three are in group 2, and last one in group 3.
我想进行一次计数匹配:前三个在组1中,第二三个在组2中,最后一个在组3中。
0 0 1998-09-21 CD O O B-Num
I'm not an expert in regex but I came up with this: 我不是正则表达式的专家,但我想出了这个:
^(\\S*)[\\t,]*(\\S*)[\\t,]*(\\S*)[\\t,]*(\\S*)[\\t,]*(\\S*)[\\t,]*(\\S*)[\\t,]*(\\S*)[\\t,]*(.*)$
This will only split everything into seven pieces, which does not meet the requirement..anyone knows how to do tasks like this? 这只会将所有内容分成七部分,这不符合要求。任何人都知道如何执行这样的任务吗?
You can change the way you're capturing a little to this: 您可以对此进行一些更改:
^(\S*[\t,]*\S*[\t,]*\S*)[\t,]*(\S*[\t,]*\S*[\t,]*\S*)[\t,]*(\S*)$
^---------------------^ ^---------------------^ ^---^
Also, you might want to change some of the quantifiers to +
. 另外,您可能需要将某些量词更改为
+
。 having all *
means that it will also attempt to match an empty string. 全部为
*
表示它还将尝试匹配一个空字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.