Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用正则表达式从字符串中提取值_Java_Regex_Parsing - Fatal编程技术网

Java 如何使用正则表达式从字符串中提取值

Java 如何使用正则表达式从字符串中提取值,java,regex,parsing,Java,Regex,Parsing,我有以下字符串: XYZ,132917057937901,150617,051244,+12.345555,+73.179481,0,153,45,11,1,3,000,00,0.0,9.23,7.40,24.74,0.0,0,0.90,0,0,345,1374,108 现在我想提取第16位9.23和第17位7.40的值 这根绳子固定在它们的位置上 如何在第16位和第17位获取值?使用String.split而不是regex: String[] split = input.split(',')

我有以下字符串:

XYZ,132917057937901,150617,051244,+12.345555,+73.179481,0,153,45,11,1,3,000,00,0.0,9.23,7.40,24.74,0.0,0,0.90,0,0,345,1374,108
现在我想提取第16位
9.23
和第17位
7.40
的值

这根绳子固定在它们的位置上


如何在第16位和第17位获取值?

使用
String.split
而不是regex:

String[] split = input.split(',');
String pos16 = split[15];
如果您确实要使用正则表达式,请使用此匹配并获得组1和组2:

Matcher m = Pattern.compile("(?:[^,]*,){15}([^,]*),([^,]*)").matcher(input);
m.find();
String pos16 = m.group(1);

正则表达式不匹配。在
{15}
之后删除