无法使用正则表达式生成随机字符串。正则表达式是指定和识别文本,字符和单词的模式的方法。您可以使用以下代码生成随机字符串。
public static String createRandomString(int length)
{
String randomString = "";
String lookup[] = null;
int upperBound = 0;
Random random = new Random();
lookup = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
upperBound = 36;
for (int i = 0; i < length; i++)
{
randomString = randomString + lookup[random.nextInt(upperBound)];
}
return randomString;
}