Find multiple line spanning text and replace using Powershell

Posted by MrGrant on Stack Overflow See other posts from Stack Overflow or by MrGrant
Published on 2010-06-16T22:53:25Z Indexed on 2010/06/16 23:22 UTC
Read the original article Hit count: 165

Filed under:
|

Hello,

I am using a regular expression search to match up and replace some text. The text can span multiple lines (may or may not have line breaks). Currently I have this:

 $regex = "\<\?php eval.*?\>"

Get-ChildItem -exclude *.bak | Where-Object {$_.Attributes -ne "Directory"} |ForEach-Object {
 $text = [string]::Join("`n", (Get-Content $_))
 $text -replace $RegEx ,"REPLACED"}

© Stack Overflow or respective owner

Related posts about regex

Related posts about powershell