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
Wildcard character (*) matches zero or more characters in the string and if the input string is secular then it gives the boolean output and if it is a string array then the matching strings will be the output as shown below. In the above example, wildcard character (*) matches the string before it (case-insensitive).
[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9. (a-z0-9) -- Explicit capture of a-z0-9 .
The period ( . ) is a wildcard character in regular expressions. It will match any character except a newline ( \n ). # This expression returns true. # The pattern matches any 4 characters except the newline.
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1. 1* means any number of ones.
Select-String will accept an array of regex patterns:
Select-String $includeRegexArray -inp $database.Name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With