Powershell 将单个字符串与多个正则表达式匹配? [英] Powershell match a single string against multiple regexs?

查看:65
本文介绍了Powershell 将单个字符串与多个正则表达式匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了依次遍历每个字符串之外,是否有更强大"的方式将单个字符串与正则表达式的数组/集合进行匹配?

Is there a more 'powershelly' way of matching a single string against an array/collection of regexes other than iterating through each one in turn?

我真正想做的是这样的事情

What I'd really like to be able to do is something this

$database.Name -match $includeRegexArray

$database.Name -match $includeRegexArray

考虑到 Powershell 的工作方式,感觉应该有比编写函数来迭代数组更好的解决方案

Given the way Powershell works it feels like there should be a nicer solution than writing a function to iterate over the array

推荐答案

Select-String 将接受一组正则表达式模式:

Select-String will accept an array of regex patterns:

Select-String $includeRegexArray -inp $database.Name

这篇关于Powershell 将单个字符串与多个正则表达式匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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