Hello Powershell guru’s,
I am looking for a way to remove all dots from a string except for the first dot.
I found this: “1.2.3.4” -replace “.(?=..)”,“”
This removes all dots except the last one, but I need to remove all dots except the first one. Any ideas?
Kind regards,
S.
Olaf
October 28, 2022, 3:31pm
2
Seguino74,
Welcome back to the forum.
May I ask what the actual job is? Is it about a version number? If that’s the case you may make your life harder than necessary.
If it’s about a version string you should treat it as such.
$Version = [version]'1.2.3.4'
You can access each individual part of a version string with its name:
$Version.Major
$Version.Minor
… and so on … and you could use this to re-join the parts in whatever way you like …
'{0}{1}.{2}.{3}' -f $Version.Major, $Version.Minor, $Version.Build, $Version.Revision
If it’s a pure string you can use -replace with the following regex:
$Version.ToString() -replace '(?<=^\d+)\.'
It removes a literal dot preceded by some digits following the start of the string.
system
Closed
February 10, 2024, 5:34pm
3
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.