[英]Regular Expression for a valid Text
我試圖創建一個驗證的正則表達式!
例如:@#$ ##
EX:測試!
例如:@#Test
例如:te#$ sT
抱歉,對於這個復雜的正則表達式,我的知識不允許我放置任何嘗試的代碼。 因為除了[ab AB !@#$%^&*()]
我一無所有
UPDATE
SDF SDF! :驗證為假
_ __ :驗證為真實(得分以下)
sadf,sdfsdf :驗證為false
空白:驗證為true
嘗試這個:
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)
"
這是我對您的建議:
^(\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.
據我了解,您只想接受包含一些字母和一些特殊字符的字符串。 所以像這樣:
[(a-zA-Z)+(\!\@\#\$\%\^\&\*\(\))+]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.