正则表达式匹配大小写混合的单词 [英] Regex to match mixed case words

查看:38
本文介绍了正则表达式匹配大小写混合的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个正则表达式来匹配由 8 个字符组成的任何单词,这些字符应该属于字符集:[A-Za-z0-9].

I want to write a regex which will match any word consisting of 8 characters and these characters should belong to the charset: [A-Za-z0-9].

但是,它们应该至少包含来自 3 个字符集(大写、小写和数字)中的每一个的一个字符.

However, they should consist of at least one character from each of the 3 charsets (uppercase, lowercase and digits).

这是我使用的正则表达式:

This is the regex I am using:

^[a-zA-Z0-9]{8}$

但是,这将匹配以下示例:

however, this will match examples like:

09823983
language
mainMenu

但我想匹配以下单词:

uXk3mHy9

我如何使用正则表达式来做到这一点?

how can I do this using a regex?

推荐答案

您可以在正则表达式前使用三个 look-ahead:

You can use three look-aheads in front of your regex:

^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]{8}$

这篇关于正则表达式匹配大小写混合的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆