Hi Guys
building a script to interegate a csv,
essentially the csv looks like
Password Age (Days)
1
43
568
90
89
32
356
i need to capture ranges 0-90, i tried the below but get 0-90 MISSING OUT THE SINGLE NUMBER 9
$_.'Password Age (Days)' -match "^(90|[0-8][0-9])$"
i can see its this part “[0-8]” but dont know how to correct without then getting 91,92,93,94 etc…
my regex sucks and i know it
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
I like this site for developing and testing regex. It will even show interactive help for each element.
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
Updated, realized it would get all the single digits except 9. This is probably not the only solution either, I am just a regex hack too, but with slightly more experience.
hi,
I’m bad with regex so I’ll try to avoid them. Why don’t you use less or equal operator and if statement?
import-csv C:\temp\psorg.csv | foreach {
if ([int]$_.'Password Age (Days)' -le 90) {$_.'Password Age (Days)'}
}
Many thanks to both, will give those a try
didnt even consider the -le method, tunnel vision
But if you really wanted RegEx, you could do this…
$PWAge = @'
1
43
568
90
89
32
356
'@
[regex]::Matches($PWAge,'(?<!\d)\d{1,2}(?!\d)').Value
1
43
90
89
32
This regex tool is pretty good may help you… https://www.workshell.co.uk/products/netregex
I used it to help me with this regex:
(.=. |\n.=)(. |\n.)(DESCRIPTION .=
I was parsing Oracle Tnsnames files.
js2010
March 14, 2018, 10:46pm
8
$a = import-csv num.csv
$a | where { $_.'Password Age (Days)' -in 0..90 }
Password Age (Days)
-------------------
1
43
90
89
32
many ways to skin a cat here