I have a string such as below:
String str="tile tile-2 tile-position-1-4"
I wish to receive the numbers in an array,such as [2,1,4].
My own solution is to break the string using split, but i am wondering if there is a shortcut using Regx
Thanks to @nitzien with Regx it tried:
String pattern= "^tile tile-(\\d*) tile-position-(\\d*)-(\\d*)$";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(str);
System.out.println(m.group(0));
System.out.println(m.group(1));
System.out.println(m.group(2));
But, it complains with:
java.lang.IllegalStateException: No match found
String[] result =Arrays.stream(str.split("\\D")).filter(s->!s.isEmpty()).toArray(String[]::new);