David Hayes
David Hayes

Reputation: 7512

Powershell match a single string against multiple regexs?

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

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

Upvotes: 5

Views: 1145

Answers (1)

Keith Hill
Keith Hill

Reputation: 201832

Select-String will accept an array of regex patterns:

Select-String $includeRegexArray -inp $database.Name

Upvotes: 5

Related Questions