您现在的位置是:网站首页> 编程资料编程资料
Powershell小技巧之判断是否包涵大小写_PowerShell_
2023-05-26
391人已围观
简介 Powershell小技巧之判断是否包涵大小写_PowerShell_
使用正则表达式可以检查一个字符中是否包涵一个大写字母:
$text1 = 'this is all lower-case' $text2 = 'this is NOT all lower-case' $text1 -cmatch '[A-Z]' $text2 -cmatch '[A-Z]'
结果将返回”true”或”false”
反过来检查是否包含小写,可以尝试这样:
$text1 = 'this is all lower-case' $text2 = 'this is NOT all lower-case' $text1 -cmatch '^[a-z\s-]*$' $text2 -cmatch '^[A-Z\s-]*$'
结果将返回”true”或”false”
总体来说,这次测试比较困难因为你需要考虑所有字符的合法性。在这个例子中,我采用了从a到z的小写字符串,空格和减号。
合法的字符串是嵌在“^”与“$”中间的(它表示行的开始和结尾)。星号代表量化前面任何合法字符串。
支持所有PS版本
您可能感兴趣的文章:
相关内容
- PowerShell小技巧之调用CloudFlare的SDK查询网站统计信息_PowerShell_
- PowerShell小技巧实现IE Web自动化_PowerShell_
- Windows Azure VM上配置FTP服务器_PowerShell_
- Powershell小技巧之查看安装的.Net framework版本信息_PowerShell_
- Powershell小技巧之非相同域或信任域也能远程_PowerShell_
- Powershell小技巧之从文件获取系统日志_PowerShell_
- Powershell小技巧之使用WMI工具_PowerShell_
- Powershell小技巧之创建一个新对象_PowerShell_
- 25个常用PowerShell命令总结_PowerShell_
- WMI入门教程之WMI中的类在哪里?_PowerShell_
