I have something like \"ali123hgj\". i want to have 123 in integer. how can i make it in java?
public static final List scanIntegers2(final String source) {
final ArrayList result = new ArrayList();
// in real life define this as a static member of the class.
// defining integers -123, 12 etc as matches.
final Pattern integerPattern = Pattern.compile("(\\-?\\d+)");
final Matcher matched = integerPattern.matcher(source);
while (matched.find()) {
result.add(Integer.valueOf(matched.group()));
}
return result;
Input "asg123d ddhd-2222-33sds --- ---222 ss---33dd 234" results in this ouput [123, -2222, -33, -222, -33, 234]