title: Replace with function instead of string with swift regex
body: <p>In Javascript, you can <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter" rel="nofollow noreferrer">replace a string with a function</a>.  Is there a way do do this in Swift with <code>NSRegularExpression</code>?</p>
  
  <p>I want to do the equivalent of</p>
  
  <pre><code>"*Hello there*".replace(/(\*).*?(\*)/g, function(match, p1, p2, p3) {
      return "&lt;i&gt;" + p2 + "&lt;/i&gt;"
  })
  </code></pre>
  
  <p>in Swift because I'm writing a markdown parser.</p>