static BigInteger[] extractIntsFromString(S s) { Pattern p = Pattern.compile("-?\\d+"); Matcher m = p.matcher(s); List list = new ArrayList(); while (m.find()) list.add(new BigInteger(m.group())); return list.toArray(new BigInteger[list.size()]); }