For an Exchange Online rule I'm trying to create a regular expression in PowerShell that matches (-match
) any case that does NOT end with '.pdf'. Sadly I'm not that experienced yet with regular expressions. I'm using the following regex testing site to test.
It seems to match the output you would get from PowerShell regex.
I have already tried the following: .?[^\.pdf]$
.
This is what I get for output:
"test.txt" -match '.?[^\.pdf]$'
→ True (this is what I want)"test.docx -match '.?[^\.pdf]$'
→ True (this is what I want)"test.pdf.txt -match '.?[^\.pdf]$'
→ True (this is what I want)"test.pdf" -match '.?[^\.pdf]$'
→ False (this is what I want)
It starts to fail with the following examples:
"test.pdd" -match '.?[^\.pdf]$'
→ False (this is NOT what I want)"test.pdx" -match '.?[^\.pdf]$'
→ False (this is NOT what I want)
I have also tried many things along the lines of: '.?(\.[^pP][^dD][^fF])$'
, but I'm experiencing similar results.