User:Frap/Reverse domain name notation

From Rosetta Code

Encyclopedic article can be found on Wikipedia.

Regex:

^[A-Za-z]{2,6}((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+$

C#[edit]

/// <summary>
/// Reverses a domain name.
/// </summary>
/// <param name="domain">A domain name.</param>
/// <returns>A string with the domain name reversed.</returns>
private static string ReverseDomainNameNotation(string domain)
{
return string.Join(".", domain.Split('.').Reverse());
}

JavaScript[edit]

function reverseDomain(domain) {
return domain.split('.').reverse().join('.');
}

Perl[edit]

sub reversedomain {
return join ".", reverse split /\./, $_[0];
}

PHP[edit]

function reverseDomain(domain) {
return implode('.', array_reverse(explode('.', domain)));
}

PowerShell[edit]

function Get-ReverseDomain($domain)
{
$segments = $domain.split('.')
[array]::reverse($segments)
return $segments -join '.';
}

Python[edit]

def reverse_domain(domain):
"""Reverses a domain name."""
return '.'.join(reversed(domain.split('.')))

Ruby[edit]

# Reverses a domain name.
def reverse_domain(domain)
domain.sp­lit('.').r­everse.j­oin('.')
end