PowerShell, 108 100 9595 85 Bytes
$i,$z=$args;$b,$s=[char[]]$z;($b+$z=$args;($z[0]+($i-split'[^\d.-]+'-ne'')-join$sjoin$z[1])+' }) >]'[($b$z[0]-32)%6]).Trim()
A slight variation(see revision history for previous versions)
Golfed another 15 bytes by removing $b
and $s
variables and changing parens on the below, thanks to TessellatingHecklerinner string.
This takes the two arguments as input toas two strings and stores them into $i
and $z
, then casts $z
aswe construct a char-array and pulls the two arguments out intonew output string. The inner parens $b-split
ands $s$i
. We with a regex to select only numeric digits, then concatenate $b-join
s back together with $i
having been split on digits and negativesthe requested delimiter. We concatenate that existwith the first character of the delimiter input (i.e.g., -ne''[
). That gets -join
ed and close it with the same indexing, into a string based on the ASCII value of the first character and finallysome formulation trickery. The outer .Trim()
to removeremoves any leading/trailing or trailing spaces.
###Old:
param($a,$b)($b[0]+(-split($a-replace"[\[\]{}()<>;,]",' ')-join$b[1])+' }) >]'[($b[0]-32)%6]).Trim()
Pretty similar to the other answers, just with PowerShell's verbose unique syntax.
###Explained:
- Takes input as two strings via
param($a,$b)
, then builds the output string via everything inside the parens()
. - We first use the first character of
$b
with$b[0]
, add that to another parens-separated dynamically built string, and then add that to the closing character. - The closing character is selected by indexing into a string based on a formula of
($b[0]-32)%6
- thanks to Danko Durbić for golfing 8 bytes here). - The inner-parens string is constructed by simply getting rid of any input junk with a regex and
-replace
ing it with a space,-split
ting that on spaces to create an array, and-join
ing that array together with the second character of$b
. - Finally, the trailing
.Trim()
removes any remaining leading or trailing spaces.