正则表达式匹配字母字符串并需要至少一个大写和一个小写(vb.net) [英] Regular expression to match alphabetic string and require at least one uppercase and one lowercase (vb.net)
本文介绍了正则表达式匹配字母字符串并需要至少一个大写和一个小写(vb.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 vb.net 中编写正则表达式字符串匹配.我试图实现的条件是字符串应该只包含字母,并且必须至少包含一个大小写字母.即 AAA-fail、aaa-fail、aAaA-pass.
I am trying to write a regular expression string match in vb.net. The condition that I am trying to implement is that the string should contain only alphabets and must contain atleast one letter of both lower and upper case. i.e AAA-fail, aaa-fail, aAaA-pass.
我想到的正则表达式是^(([az]+[AZ]+)+|([AZ]+[az]+)+)$
有人可以推荐一些更好/更简单的正则表达式吗?
Can someone suggest some better/simpler regular expression for the same?
推荐答案
您创建的正则表达式在某些情况下会失败,例如aAb".我认为以下方法更适合您:
The regex you created will fail under some conditions, such as "aAb". I think the following will work better for you:
^(?:[a-z]+[A-Z]+|[A-Z]+[a-z]+)(?:[a-zA-Z])*$
这篇关于正则表达式匹配字母字符串并需要至少一个大写和一个小写(vb.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文