问题描述
- JAVA字符串形式数值数组取值
-
字符串格式是这样的[[x1,y1,v1],[x2,y2,v2],[x3,y3,v3] ....[xn,yn,vn]]。想按顺序取出里面的v1...vn放到一个数组或者集合里,怎样最简洁?
解决方案
String s="[[x1,y1,v1],[x2,y2,v2],[x3,y3,v3] ....[xn,yn,vn]]";
Pattern pattern=Pattern.compile("vd+");
Matcher matcher = pattern.matcher(s);
while (matcher.find()){
System.out.println(matcher.start());
}
解决方案二:
String s="[[x1,y1,v1],[x2,y2,v2],[x3,y3,v3] ....[xn,yn,vn]]";
Pattern pattern=Pattern.compile("v\d+");
Matcher matcher = pattern.matcher(s);
while (matcher.find()){
System.out.println(matcher.start());
}
解决方案三:
Pattern pattern=Pattern.compile("v\d+");
->
Pattern pattern=Pattern.compile("(?<=\d+\,\d+\,)\d+");
解决方案四:
str.replace(/([xd+,yd+,)|((?=d+)])/g,"")
时间: 2024-10-27 18:55:38