New answers tagged

4

Charcoal, 74 68 bytes FS«W∧υ›№]}ι⁼§υ±¹ι≔⁺ω⊟υω≔⁺ωιω≡ι]F¬∧υ⊟υ≔⁺[ωω}F¬∧υ⊟υ≔⁺{ωω[⊞υ]¦{⊞υ}»ω↑⮌υ Try it online! Link is to verbose version of code. Explanation: FS« Loop over the characters of the input. W∧υ›№]}ι⁼§υ±¹ι≔⁺ω⊟υω If the current character is a closing bracket and we're expecting the other sort of closing bracket then append that bracket now. Keep ...


2

JavaScript (ES6),  145  142 bytes s=>[...s].map(c=>o+=(i=(S='[]{}').indexOf(c)^1)&1?(s=S[i]+s,c):i<0?c:(g=_=>s?(C=s[s=s.slice(1),0])==c?c:C+g():(p=S[i]+p,c))(),s=o=p='')&&p+o+s Try it online!


2

Retina 0.8.2, 269 bytes \[(\[(?=.*(]))|\{(?=.*(?<2>}))|[^][}{]|(?<-2>\2))*(?(2)(?!))(?=}|$) $&] \{(\[(?=.*(]))|\{(?=.*(?<2>}))|[^][}{]|(?<-2>\2))*(?(2)(?!))(?=]|$) $&} ^(\[(?=.*(]))|\{(?=.*(?<2>}))|[^][}{]|(?<-2>\2))*(?(2)$)] [$& }`^(\[(?=.*(]))|\{(?=.*(?<2>}))|[^][}{]|(?<-2>\2))*(?(2)$)} {$& ...


Top 50 recent answers are included