【发布时间】:2016-09-03 02:22:11
【问题描述】:
该行应该是:
- 包含字母数字、点号
.和减号-、空格、下划线、斜线 - 如果没有字母数字,则正则表达式应返回 false
我写了以下Regex 模式:
string pattern = @"^[a-zA-Z0-9._\+\-\/\s]+$";
第二个条件不满足:
string s1 = "."; // or dot, space, underscore, slash
// Compare a string against the regular expression
var isOK = new Regex(pattern).IsMatch(s1); // true, but I would like to be false
您能告诉我创建Regex 模式的正确方法吗?
【问题讨论】:
-
^(?=.*[a-zA-Z0-9])your regex here或者,(?=.*[\p{L}\p{N}])