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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -