我试图创建一个验证!!
的正则表达式Ex:@#$ ##
EX:测试!!
Ex:@#Test
Ex:te#$ sT
我道歉,对于这个复杂的正则表达式,我的知识不允许我输入我尝试的任何代码。因为我除了[a-b A-B !@#$%^&*()]
更新
sdf SDF!:验证为false
_ __ :验证为真(在得分下)
sadf,sdfsdf :验证为false
空格:验证为真
答案 0 :(得分:3)
试试这个:
foundMatch = Regex.IsMatch(subjectString, @"^(?!\W*$)(?=[ .\w]\w*\W*$).*$");
我试图弄明白你的意思让我很头疼。你必须学会更好地表达自己。
<强>解释强>
"
^ # Assert position at the beginning of the string
(?! # Assert that it is impossible to match the regex below starting at this position (negative lookahead)
\W # Match a single character that is a “non-word character”
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
$ # Assert position at the end of the string (or before the line break at the end of the string, if any)
)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
[ .\w] # Match a single character present in the list below
# One of the characters “ .”
# A word character (letters, digits, etc.)
\w # Match a single character that is a “word character” (letters, digits, etc.)
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\W # Match a single character that is a “non-word character”
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
$ # Assert position at the end of the string (or before the line break at the end of the string, if any)
)
. # Match any single character that is not a line break character
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
$ # Assert position at the end of the string (or before the line break at the end of the string, if any)
"
答案 1 :(得分:1)
以下是我的建议:
^(\s|\w)\w*\W*$
<强>解释强>
^(\s|\w) the first character has to be a whitespace or a alphanumeric (including underscore)
\w* followed by any number of alphanumeric (including underscore)
\W*$ at the end of the string any number of any *except* alphanumeric characters are allowed.
答案 2 :(得分:1)
据我所知,你只想接受包含一些字母然后是一些特殊字符的字符串。所以像这样:
[(a-zA-Z)+(\!\@\#\$\%\^\&\*\(\))+]