简体   繁体   English

Java正则表达式匹配列表中的前6位数字

[英]java regular expression matches first 6 digits in a list

I have a range of numbers separated by comma, which is stored in a csv file. 我有一系列用逗号分隔的数字,这些数字存储在一个csv文件中。 I am trying to match first 6 digits, for example: "130001X, XYZ" can be considered a group of digits in which X can be anything (0-9). 我正在尝试匹配前6位数字,例如:“ 130001X,XYZ”可以被视为一组数字,其中X可以是任何数字(0-9)。

Is it possible? 可能吗? Can I use Java regular expression to match these and group them to a list? 我可以使用Java正则表达式来匹配它们并将它们分组到一个列表中吗?

Thanks! 谢谢!

1300010,10 1300011,10 1300012,22 1300013,22 1300014,22 1300015,533 1300016,535 1300017,531 1300018,22 1300019,22 1300010,10 1300011,10 1300012,22 1300013,22 1300014,22 1300015,533 1300016,535 1300017,531 1300018,22 1300019,22

1300050,20 1300051,20 1300052,20 1300053,20 1300054,20 1300055,20 1300056,20 1300057,20 1300058,20 1300059,20 1300050,20 1300051,20 1300052,20 1300053,20 1300054,20 1300055,20 1300056,20 1300057,20 1300058,20 1300059,20

I'm not sure if I understood your question. 我不确定是否理解您的问题。 But if you want to match the numbers having 13000x,xxx then you can use a regex like this: 但是,如果要匹配具有13000x,xxx的数字,则可以使用如下正则表达式:

\b130001\d,\d{3}\b

Live demo 现场演示

Assuming that X is the same in X,X and YZ are also two random digits 假设X在X,X相同X,XYZ也是两个随机数字

\b130001(\d),\1\d{2}\b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM