title: Lambda Expression in Powershell
body: <p>I have a code in C# which uses lambda expressions for delegate passing to a method. How can I achieve this in PowerShell. For example the following is a C# code:</p>
  
  <pre><code>string input = "(,)(;)(:)(!)";
  string pattern = @"\((?&lt;val&gt;[\,\!\;\:])\)";
  var r = new Regex(pattern);
  string result = r.Replace(input, m =&gt;
      {
          if (m.Groups["val"].Value == ";") return "[1]";
          else return "[0]";
      });
  Console.WriteLine(result);
  </code></pre>
  
  <p>And this is the PowerShell script without the lambda-expression in place:</p>
  
  <pre><code>$input = "(,)(;)(:)(!)";
  $pattern = "\((?&lt;val&gt;[\,\!\;\:])\)";
  $r = New-Object System.Text.RegularExpressions.Regex $pattern
  $result = $r.Replace($input, "WHAT HERE?")
  Write-Host $result
  </code></pre>
  
  <p><strong>Note:</strong> my question is not about solving this regular-expression problem. I just want to know how to pass a lambda expression to a method that receives delegates in PowerShell.</p>