Powershell 将单个字符串与多个正则表达式匹配?

编程入门 行业动态 更新时间:2024-10-23 12:24:48
本文介绍了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 将单个字符串与多个正则表达式匹配?

本文发布于:2023-10-23 13:50:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521006.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   字符串   正则表达式   Powershell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!