Use Java [Close] to find the index of the first occurrence of integer from the string
•
Java
I have string xxxy 1 / 1 / 2. I need to use java to find the index of integer for the first time The output will be the first "1" index I need regular expressions
Solution
You don't use regular expressions, but if you have to use them:
String s = "xxxxy 1/1/2"; Pattern pattern = Pattern.compile("^\\D*(\\d)"); Matcher matcher = pattern.matcher(s); matcher.find(); System.out.println(matcher.start(1));
Output: 6
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码