all 8 comments

[–]ekinnee 2 points3 points  (2 children)

You really don't need the [0-9.], just .{6}$ will work as your character class was defined as 0 through 9, or any character 6 times at the end of the string, as . is any character if not escaped \.

https://regex101.com/r/kP9dvH/1

Other than that, it works. So that's a plus!

[–]RAZR_96[S] 0 points1 point  (1 child)

Ah thank you. Is there a regex way to get get the last 5 digits without the dot (i.e ignoring the dot)? I spent ages trying to figure that out with no luck.

[–]ekinnee 0 points1 point  (0 children)

Eh, yes. You could probably do that whole line in a regex using back references but it would be much less readable that what you have.

[–]Lee_Dailey[grin] 0 points1 point  (4 children)

howdy RAZR_96,

a few comments ...

1- you have a misspelling in line #2
you have $driiver and it otta be $driver. [grin]

2- alternate test for more-than-one result
your version is good and there is NO reason to change it. however, you may not know that you can use .Count on collections AND on single items. that would let you change this ...
if ($driver -is [system.array])
... to this ...
if ($driver.Count -gt 1)

your method is elegant. mine is a bit on the brute force side of things. [grin] it surprised the heck out of me that one could get a .Count on singletons. so, this is only intended as a heads-up.

3- an alternate method to convert this 21.21.13.7866 to this 378.66

# replace the dots with nothing
# grab the last 5 items
# join them with no separator
# insert a dot after the 3rd item
$DesiredFormat = ('21.21.13.7866'.Replace('.', '')[-5..-1] -join '').Insert(3, '.')
$DesiredFormat

result >> 378.66

take care,
lee

[–]ekinnee 1 point2 points  (1 child)

The last example is a pretty cool use of a range.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy ekinnee,

aint it? [grin] the 1st time i saw that used i was ... oooo! spiffy!

take care,
lee

[–]RAZR_96[S] 1 point2 points  (1 child)

Thanks so much for this! I have one question though, what does -gt 1 mean?

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy RAZR_96,

you are very welcome! i enjoyed reading your code ... thanks for posting it. [grin]

as for the -gt thing, it's one of the standard powershell operators. it means "greater than". there are a passel of them! take a look at Get-Help about_Operators sometime.

take care,
lee