I am trying to find a way to replace the same string with different values in a text file using powershell. The word is the same with special characters (e.g "[Placeholder]"). This is for a .json file that looks something similar to this.
Line1:
Line2:
Line3: [Placeholder]
Line4: [Placeholder]
The idea is to change the string [Placeholder] on line 3 with the version and line 4 with the current date. When i try to do this with the following code it automatically replaces both [Placeholder]'s with the version and i am struggling to find a way to have line 3 be the version and 4 the date
$currentVersion = "v.1.2.3.4"
$currentDate = "08/08/2021"
$original_file = 'C:\Users\samue\Desktop\D\V1\hehehehe.txt'
(Get-Content $original_file) | Foreach-Object {
$_ -replace ([regex]::Escape('[Placeholder]')), $currentVersion `
-replace ([regex]::Escape('[Placeholder]')), $currentDate
} | Set-Content $original_file
As you can see it will replace all [placeholder]'s with $currentVersion because that is the first thing it finds but I need some help on maybe how to use regex to match and then replace the word
Line1:
Line2:
Line3: v.1.2.3.4
Line4: v.1.2.3.4