正则表达式结尾处没有数字和字符串的开头

时间:2021-07-26 21:43:45

I've been searching for a Regex to match a string that has no digit at the end and the beginning. Since this is a password complexity requirement I have to implement, I thought that there would be at least one example for this use case, but I couldn't find anything like that. Also my own attempts were not successful to create such a Regex.

我一直在寻找一个正则表达式来匹配一个在结尾和开头没有数字的字符串。由于这是我必须实现的密码复杂性要求,我认为这个用例至少会有一个例子,但我找不到类似的东西。我自己的尝试也没有成功创建这样的正则表达式。

Examples

例子

abc2 - no match
1bca - no match
bac  - match
b1b1 - no match
b1b  - match
1c1c - no match

Thanks a lot in advance.

非常感谢提前。

2 个解决方案

#1


2  

You can use:

您可以使用:

^[a-zA-Z][a-zA-Z0-9]*[a-zA-Z]$

but just remember that this regex will require input to be at least 2 characters length.

但请记住,此正则表达式将要求输入至少2个字符长度。

To match characters other than just alpha-numerals you can use:

要匹配除字母以外的字符,您可以使用:

You can use:

您可以使用:

/^\D.*?\D$/gm

Regexr Demo

Regexr演示

#2


0  

Check if this works:

检查是否有效:

^\D\w*\D$

#1


2  

You can use:

您可以使用:

^[a-zA-Z][a-zA-Z0-9]*[a-zA-Z]$

but just remember that this regex will require input to be at least 2 characters length.

但请记住,此正则表达式将要求输入至少2个字符长度。

To match characters other than just alpha-numerals you can use:

要匹配除字母以外的字符,您可以使用:

You can use:

您可以使用:

/^\D.*?\D$/gm

Regexr Demo

Regexr演示

#2


0  

Check if this works:

检查是否有效:

^\D\w*\D$