0

I want to extract numbers from a string like:

str="good_mor9ni13ng_23guys ";

The output should be an array [9,13,23]. How should I proceed?

Karup
  • 1,944
  • 2
  • 20
  • 46

1 Answers1

7

You could do it like this:

List<String> matches = new ArrayList<String>();
Matcher m = Pattern.compile("[0-9]+").matcher("good_mor9ni13ng_23guys");
while (m.find()) {
    matches.add(m.group());
}
Kai Sternad
  • 21,414
  • 7
  • 45
  • 42