mahesh
mahesh

Reputation: 478

PowerShell regex to filter values between {{ and }}

I'm trying to write a regex to filter the values, that exist between curly braces: Example: $path = C:\serices\ApplicationName\{{NewFolderName}}

I want to filter the value "NewFolderName" from the above variable. Once I execute, I want to see "NewFolderName" in my output. I'm using PowerShell version 2.0. Can someone please suggest me the possible solution.

Thanks in advance.

Upvotes: 1

Views: 436

Answers (2)

Michael Noe
Michael Noe

Reputation: 82

Here's the full powershell for your question.

$path = "C:\users\{{XXX}}\Downloads\{{YYY}}\AppName"
$matches = [regex]::Matches($path,"\{{2}(.*?)\}{2}").value

Upvotes: 1

Jan
Jan

Reputation: 43179

One way would be:

\{{2}(.*?)\}{2}

See a demo on ideone.com.

Upvotes: 2

Related Questions