I'm currently working on a WSUS-Update automization and I'd like to get all Updates that don't start with "(German|English) Language Pack".
This is what I got so far:
[regex]$reg = "(?<!German|English|English \(United States\)) Language Pack"
$LanguagePacks = $updates.Where({ $_.Title -match $reg })
That works, but I also get updates like: Windows Internet Explorer 9 Language Pack for Windows 7 for x64-based Systems
But I also want to get Updates in the following syntax: [Language] Language Pack e.g. Finnish Language Pack
So I tried to use the '^' anchor to determine the start of the String
[regex]$reg = "^(?<!German|English|English \(United States\)) Language Pack"
$LanguagePacks = $updates.Where({ $_.Title -match $reg })
But in this case the result is empty :(
You may use
(?<!^(?:German|English(?:\s+\(United States\))?)\s*)Language Pack
See the regex demo
It matches Language Pack if it is not preceded with German, English, or English (United States) at the start of the string.
Details
(?<! - start of a negative lookbehind that fails the match if, immediately to the left of the current location, there are patterns:
^ - start of string(?: - start of an alternation non-capturing group:
German - a literal substring| - orEnglish - a literal substring(?:\s+\(United States\))? - an optional non-capturing group matches 1 or 0 occurrences of:
\s+ - 1 or more whitespaces\(United States\) - a literal (United States) substring) - end of the alternation group\s* - 0+ whitespaces) - end of the lookbehindLanguage Pack - a literal substringIf 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