Created
July 7, 2017 06:27
-
-
Save stanislavhordiyenko/5f0edd8ccded5bc442c7566895690759 to your computer and use it in GitHub Desktop.
Replace text in multi line string in PowerShell. Below you can find several powershell examples how to replace text in a multi line string with regular expressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$text = " | |
This is | |
__ | |
a multi line | |
string | |
__ | |
with some marks in it. | |
" | |
# Here we remove a text in the multiline string between two marks | |
$text = $text -Replace "(?ms)__.*?__`n?`n?", "" | |
# We use Trim() method to remove new line from the beginning and the end of the string | |
Write-Output $text.Trim() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$text = " | |
This is | |
__ | |
a multi line | |
string | |
__ | |
with some marks in it. | |
" | |
# Here we remove marks in the multiline string | |
$text = $text -Replace "(?ms)^__`n?`n?", "" | |
# We use Trim() method to remove new line from the beginning and the end of the string as well | |
Write-Output $text.Trim() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment