Last active
March 14, 2016 11:04
-
-
Save jatubio/5a61ea513cfa7ee93b03 to your computer and use it in GitHub Desktop.
PowerShell. Ini Files. Replacing a value in a key inside a section sample 2
This file contains 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
# Ini files | |
# Replacing a value in a key inside a section sample | |
# | |
# RegEx101 Test (https://regex101.com/r/uC0cC3/1) | |
# | |
# http://stackoverflow.com/questions/29688299/powershell-and-regex-how-to-replace-a-ini-name-value-pair-inside-a-named-sectio/29688435#29688435 | |
# Ini files | |
# Replacing a value in a key inside a section sample | |
# | |
# Works on RegEx101 (https://regex101.com/r/uC0cC3/1) | |
# | |
# But not on PowerShell | |
# | |
# http://stackoverflow.com/questions/29688299/powershell-and-regex-how-to-replace-a-ini-name-value-pair-inside-a-named-sectio/29688435#29688435 | |
$Path="C:\Temp\prueba.ini" | |
@" | |
[Sky] | |
Size=Big | |
Color=White | |
[Home] | |
Color=Black | |
"@ | Set-content $Path | |
$Section="Sky" | |
$Name="Color" | |
$Value="Blue" | |
(Get-Content $Path) -join "`n" -replace "(?m)(?<=\[$Section\])([^\[]*$Name=)(.+?)$","`$1$Value" | Set-Content $Path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment