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
  • 2,024
  • 3
  • 22
  • 48

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
  • 22,214
  • 7
  • 47
  • 42