Powershell Regex to Find and Remove a Function
12:02 05 Oct 2011

I'm trying to find a function in a few hundred pages and remove it using Powershell. I can match on a single line but I'm having issues getting a multi-line match to work. Any help would be appreciated.

Function I'm trying to find:

Protected Function MyFunction(ByVal ID As Integer) As Boolean
    Return list.IsMyFunction()  
End Function

Code I'm using that won't match multi-line:

gci -recurse | ?{$_.Name -match "(?i)MyPage.*\.aspx"} | %{
  $c = gc $_.FullName;
  if ($c -match "(?m)Protected Function MyFunction\(ByVal ID As Integer\) As Boolean.*End Function")  {
    $_.Fullname | write-host;
  }
}
regex powershell