This is my first question here. I am just beginning with Powershell.
Let's say I have a text file and I want to match only the lines with a length greater than 10 characters. So I made a really simple regex.
$reg = "^\w{0,10}$"
And I use the notmatch operator.
$myTextFile | Select-String -NotMatch $reg
This is not working. I also tried
$reg = "^[a-zA-Z0-9]{0,10}$"
but this is not working either.
Any clue for me? Thanks a lot!
You don't need a regex match. Just do this:
Get-Content $myTextFile | ?{$_.Length -gt 10}
If you want to do it with a regex, the dot matches any character. This will work...
Get-Content $myTextFile | Select-String -NotMatch '^.{0,10}$'
...but this is simpler:
Get-Content $myTextFile | Select-String '.{11,}'
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