Paul S.
Paul S.

Reputation: 1352

How to remove curly braces from string in Powershell

How would I remove the {} around a string like the following? {636D9115-E54E-4673-B992-B51A8F8DDC8B} I just want to return the following: 636D9115-E54E-4673-B992-B51A8F8DDC8B

Upvotes: 3

Views: 13261

Answers (1)

Loïc MICHEL
Loïc MICHEL

Reputation: 26120

Using trim :

"{636D9115-E54E-4673-B992-B51A8F8DDC8B}".trim('{}') 

Using multiple replace :

"{636D9115-E54E-4673-B992-B51A8F8DDC8B}".Replace('{','').Replace('}','')

Using Replace with RegEx

"{636D9115-E54E-4673-B992-B51A8F8DDC8B}" -replace '\{(.*)\}','$1'

Using pure RegEx :

"{636D9115-E54E-4673-B992-B51A8F8DDC8B}" -match '\{(.*)\}'
$Matches[1]

Upvotes: 7

Related Questions