本文介绍了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 将单个字符串与多个正则表达式匹配?
发布评论