Answers for "regex for matching only numbers java"

0

java regex 10 digit number

String regex = "^\\d{10}$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher("9876543210");
matcher.matches(); // returns true if pattern matches, else returns false
Posted by: Guest on February-02-2022
0

number of matches regex java

// Java 9+
long matches = matcher.results().count();

// Java 8-
int count = 0;
while (matcher.find())
{
	count++;
}
Posted by: Guest on June-16-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language