I would like to use PowerShell to modify a text file.
I would like to -replace:
[REPLACE
at the beginning of each line withENJOY
LINE]
at the end of each line withLIFE
- only if the line starts with
[REPLACE
and ends withLINE]
What would be the regex expression used in -replace to match this request ?
Example - File Input
[REPLACE_IN_THIS_LINE]
[DO_NOT_REPLACE_IN_THIS_LINE_PLEASE]
[REPLACE_VERY_MUCH_IN_THIS_LINE]
Do not replace in this line[REPLACE_IN_THIS_LINE]
Example - File Output
ENJOY_IN_THIS_LIFE
[DO_NOT_REPLACE_IN_THIS_LINE_PLEASE]
ENJOY_VERY_MUCH_IN_THIS_LIFE
Do not replace in this line[REPLACE_IN_THIS_LINE]
As you can see, in this example, only 2nd and 4th lines have changed...
I came up with this for matching the string: -match "^\[REPLACE.*LINE\]$"
but I don't know how to use -replace
to correctly replace...