CoreJava/test/RegexTest.java

17 lines
505 B
Java
Raw Permalink Normal View History

2024-05-15 23:50:53 +08:00
package test;
public class RegexTest {
public static void main(String[] args) {
String regex = "^[a-zA-Z][a-zA-Z1-9]*$";
String testString = "Abc123"; // 测试字符串
boolean matches = testString.matches(regex);
if (matches) {
System.out.println("字符串仅由字母和数字1-9组成");
} else {
System.out.println("字符串包含非字母或非数字1-9的字符");
}
}
}