Extract first found int from String

So I have Strings 22test12344DC and 1name23234343dc

I want the best way to extract the first found full int from a String.

So this would return 22 and 1 from the above examples. The first full int’s found

I tried this way, but I don’t want any values after the first char.

mystr.split("[a-z]")[0]

Try this.

String s = "22test12344DC";
String firstInt = s.replaceFirst(".*?(//d+).*", "$1");
System.out.println(firstInt);

result:

22

Using regex and the right pattern will do the trick:
here is one example

Pattern.compile("//d+|//D+")

then break the while loop since you need only the 1st match

String myCodeString = "22test12344DC";
myCodeString = "1name23234343dc";
Matcher matcher = Pattern.compile("//d+|//D+").matcher(myCodeString);

while (matcher.find()) {
    System.out.println(matcher.group());
    break;
}