Powershell replace regex between two tags -
Powershell replace regex between two tags -
given block of arbitrary text enclosed specific tags, replace whole chunk else (in example, "banana")
$newvar = $oldvar -replace "<!-- url -->(*.)<!-- end -->","banana"
is there mode in ps regex not require escaping , can syntax simple accomplish replacement?
update: understand should .*
, not *.
, still no dice. match covers multiple lines, if adds complexity regex or requires other options.
it looks me have .*
in reverse (*.
). apart that, try:
$newvar = $oldvar -creplace '(?s)<!-- url -->.*?<!-- end -->', 'banana'
in response comments, have made .*?
lazy not "overmatch" (for details on lazy vs. greedy, see reference section) also in reference comments, (?s)
activates dotall
mode, allowing .*?
match across multiple lines. reference
the many degrees of regex greed
regex powershell
Comments
Post a Comment