Regex on Powershell script: Replace till end of line -


i have config files structured like:

path_key=c:\\dir\\project

foo=bar

i want write small script replaces key current folder. i'm trying replace "path_key=..." "path_key=$psscriptroot"

my code far:

$cfgs = get-childitem $psscriptroot -filter *name*.cfg  foreach ($cfg in $cfgs)  {   (  get-content $cfg) -replace 'path_key=.*?\n','path_key=$psscriptroot' | set-content $cfg } 

but regular expression take till end of line not working. appreciated!

you can use

'(?m)^path_key=.*'  

or

'path_key=.*' 

note $ in replacement should doubled denote single $, not problem unless there digit after it.

see demo:

enter image description here


Comments