Java: Check if regex pattern matches
25 December 2023 (Updated 25 December 2023)
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String input = "12345"; // Example string
// Check if the string contains only digits
boolean isOnlyDigits = Pattern.matches("\\d+", input);
System.out.println("Does the string contain only digits? " + isOnlyDigits);
}
}
Tagged:
Java
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment