public static void main(String[] a){ String regex="[0-9]*"; String str="珠宝/钻石/翡翠/黄金(17048) "; String[] result=getStrExpression(regex,str); for(String s:result){ System.out.println(s); }}public static int[] b = new int[9]; public static String[] getStrExpression(String regex,String str){
List<String> temp = new ArrayList<String>(); Pattern p = Pattern.compile(regex); Matcher m = p.matcher(str); while(m.find()){ temp.add(m.group()); } String[] result=new String[temp.size()]; temp.toArray(result); return result; }
String regex = "([\\u4e00-\\u9fa5]+/?)+\\((\\d+)\\)"; String str = "珠宝/钻石/翡翠/黄金(17048)"; Matcher m = Pattern.compile(regex).matcher(str); while (m.find()) System.out.println(m.group(2));
String aa = "珠宝/钻石/翡翠/黄金(17048)"; Pattern p = Pattern.compile("([^\\(])(\\d+)"); Matcher m = p.matcher(aa); while (m.find()) { System.out.println(m.group()); }
public static void main(String[] a){
String regex="[0-9]*";
String str="珠宝/钻石/翡翠/黄金(17048) ";
String[] result=getStrExpression(regex,str);
for(String s:result){
System.out.println(s);
}}public static int[] b = new int[9];
public static String[] getStrExpression(String regex,String str){
List<String> temp = new ArrayList<String>();
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
while(m.find()){
temp.add(m.group());
}
String[] result=new String[temp.size()];
temp.toArray(result);
return result;
}
String regex = "([\\u4e00-\\u9fa5]+/?)+\\((\\d+)\\)";
String str = "珠宝/钻石/翡翠/黄金(17048)";
Matcher m = Pattern.compile(regex).matcher(str);
while (m.find())
System.out.println(m.group(2));
Pattern p = Pattern.compile("([^\\(])(\\d+)");
Matcher m = p.matcher(aa);
while (m.find()) {
System.out.println(m.group());
}