【发布时间】:2015-08-27 08:51:59
【问题描述】:
我想对下面的字符串做一个正则表达式:
String s = "fdrt45B45"; // s is a password (just an example) with only
// letters and digits(must have letters and digits)
我尝试过这种模式:
String pattern= "^(\\w{1,}|\\d{1,})$"; //but it doesn't work
如果我的密码不包含字母或数字,我想得到一个不匹配,如果它同时包含两者,我想得到一个匹配。
我知道:\w is a word character: [a-zA-Z_0-9] 和 \d is a digit: [0-9],但我不能混合使用 \w and \d 来获得我想要的东西。非常感谢新手的任何帮助或提示。
【问题讨论】:
-
在发布之前在 SO 上搜索此类问题。