import Cocoa var vars = [ "AdobeCommon": "/Library/Application Support/Adobe", "df": "shouldn't get replaced", "durq": "wurqd!", "AdobeProgramFiles": "/Applications" ] func parseVars(_ str: String) -> String { var out = str var substr = Substring(str) while let closeIndex = substr.lastIndex(of: "]") { substr = str[.. asdfsdfkdj[AdobeCommon]][[df[]]testtt2][[durq]] // => asdfsdfkdj/Library/Application Support/Adobe][[df[]]testtt2][wurqd!] // => /Applications/Adobe Photoshop 2020