62,634
社区成员




import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test{
public static void main(String[] args){
String content = "dosth(a:Int, b:int ,c :string)";
String regex = ":\\s*(?<type>[^,)]+?)\\s*(?=[,)])";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(content);
while(matcher.find()){
System.out.println("'" + matcher.group("type") + "'");
}
}
}
public static List<String> getTypes(String str) {
List<String> result = new ArrayList<String>();
Matcher m = Pattern.compile("(?<=:\\s{0,10})\\w+").matcher(str);
while (m.find()) {
result.add(m.group());
}
return result;
}