2

How can Match Digit Integer from a Strings and return the Integer value.? e.g;

String = "Color Red, Size 32 / Text text";

I would like to get from this string that "32" Integer value.

many thanks in advance.

regards, Koko

2 Answers 2

4
public static void main(String[] args) {
    String s = "Color Red, Size 32 / Text text";
    Matcher matcher = Pattern.compile("\\d+").matcher(s);
    if (matcher.find()) {
      String find = matcher.group();
      Integer i = Integer.parseInt(find);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

try this code

Pattern p = Pattern.compile("^[a-zA-Z]+([0-9]+).*");
Matcher m = p.matcher("Testing1234Testing");

if (m.find()) {
    System.out.println(m.group(1));
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.