Change Value Order in String

I need some help on reordering my string value for ReverseDNS.

Currently String:
I want it to be:

I tried use regex to switch the string in reverse but it does all the values:

split and then reassemble in reverse

$IPOctects = "" -split "\."
$IP = "$($IPOctects[3]).$($IPOctects[2]).$($IPOctects[1]).$($IPOctects[0])"

Thanks Curtis, that’s exactly what I was trying to accomplish

Or split into an array, reverse the array, and join string again

PS C:\> $String = ''
PS C:\> $String

PS C:\> $Array = $String.Split('.')
PS C:\> [array]::Reverse($Array)
PS C:\> $Reversed = $Array -join '.'

PS C:\> $Reversed


$IP = "".split(".")
$IP -join "."

ah, bet me to the other option Christian :smiley:

Found another interesting regex way here:

$String = ''
(New-Object RegEx '[^\.]+', 'RightToLeft').Matches($String) -join '.'

I was actually going to suggest the reverse method also. However I got stuck for a couple of minutes due to the fact that the static reverse method does not return anything (void) and the signature does not suggest that is takes a [ref] variable ( static void Reverse(array array)). As it is a void, it should not return anything, however how does that work without [ref]?

Is there a way to have the input as a variable? Instead of a static entry of, the variable may contain more than one entry.

$IPs = ‘’,‘’

but of course there is. Here is an advanced function that supports pipeline input as well: