Replace in text file strings beteween specific text marker using wildcards

Hi.

I like to read a text and replace (remove) text between specif makler but using wildcards.

Ex Example1

{aaa}value1
{bbbbbbb}value2

I would remove {x} where x can be any character strings type and lenght to get just a list like

value1
value2

and save in an output etxt file.

  • Example 2

Input etxt file like this

value1
value1

I’d like to remove and and et a list like

value1
value2

and save it in an output etxt file.

How can do it with Powershell?

Thanks.

Have you tried anything yet in Powershell? Most forums aren’t about writing code for people but rather helping people with what they’ve got.
Your first example should be achievable with “Replace” and regex. I suggest using Regex101.com to test your matching statements.

Then your second one, if I’m understanding it right, could probably be done with Sort-Object and the -Unique switch parameter.

If you want to remove all characters before a specified value:

$string = "xyzValue"
$newString = $string -replace '^.*Value', 'Value'
Write-Output $newString

if you want to remove all characters before and after a specified value:

$string = "XyZValuea1b2c3"
$newString = $string -replace '^.*Value', 'Value' -replace 'Value.*$', 'Value'
Write-Output $newString

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.