简体   繁体   English

.NET正则表达式

[英]Regular Expressions .NET

I need a regular expression for some arguments that must match on a string. 对于某些必须在字符串上匹配的参数,我需要一个正则表达式。

here it is... 这里是...

  1. The string exists out of minimum 8 en maximum 20 characters. 该字符串不超过8个字符,最多20个字符。

  2. These characters of this string may be characters of the alfabet or special chars --With other words..all charachters except from the whitespaces 此字符串的这些字符可能是alfabet或特殊字符的字符-换句话说..除空白之外的所有字符

  3. In the complete string there must be atleast 1 number. 在完整的字符串中,必须至少有1个数字。

  4. The string cannot start with a number or an underscore 字符串不能以数字或下划线开头

  5. The last 2 characters of the string must be identical, But it doenst matter if those last --identical characters are capital or non-capital (case insensitive) 字符串的最后两个字符必须相同,但是最后两个相同的字符是大写还是非大写(区分大小写)并不重要

Must match all : 必须符合所有条件:

+234567899
a_1de*Gg
xy1Me*__
!41deF_hij2lMnopq3ss
C234567890123$^67800
*5555555
sDF564zer""
!!!!!!!!!4!!!!!!!!!!
abcdefghijklmnopq9ss

May not match : 可能不匹配:

Cannot be less then 8 or more then 20 chars: 不能少于8个或大于20个字符:

a_1+Eff
B41def_hIJ2lmnopq3stt

Cannot contain a whitespace: 不能包含空格:

A_4 e*gg
b41def_Hij2l nopq3ss

Cannot start with a number or an underscore: __1+Eff 841DEf_hij2lmnopq3stt 无法以数字或下划线开头:__1 + Eff 841DEf_hij2lmnopq3stt

cannot end on 2 diffrent characters: 不能以2个不同的字符结尾:

a_1+eFg
b41DEf_hij2lmnopq3st

Cannot be without a number in the string: 字符串中不能没有数字:

abCDefghijklmnopqrss
abcdef+++dF
!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------

This is what I have so far...But I'm really breaking my head on this... If you Don't know the answer completely it's not a problem... I just want to get in the right direction 到目前为止,这就是我的意思。。。但是我真的很伤脑筋...如果您不完全知道答案,那不是问题...我只是想朝正确的方向前进

([^0-9_])(?=.*\d)(\S{8,20})(?i:[\S])\1

If you can use multiple regexes, try these: 如果可以使用多个正则表达式,请尝试以下操作:

\S{8,20}

[^_0-9].*\d.*

.*(?i)(.)\1

If it must be one, use this: 如果必须是一个,请使用以下命令:

^[^_\s\d](?=.*\d)\S{5,17}(?i)(\S)\1$

(I must give Casmir credit for helping me find a bug in this last one.) (我必须感谢卡斯米尔(Casmir)帮助我在上一个错误中发现错误。)

EDIT: 编辑:

This is 这是

  1. any one character, other than an underscore, space, or digit. 除下划线,空格或数字外的任何一个字符。

  2. (which must be followed by any characters and then a digit) (必须后面跟任何字符,然后是数字)

  3. then five to seventeen non-whitespace characters 然后是五到十七个非空白字符

  4. then (case-insensitive from now on), a whitespace character, followed by the same character 然后(从现在开始不区分大小写),一个空格字符,后跟相同的字符

您可以尝试以下方法:

^[^\s\d_](?=.*\d)\S{5,17}(?i)(\S)\1$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM