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)的字符"); } } }