title: SSRS function with regex
body: <p>I am creating a report using SSRS for a phone number field in my database as a string value.  I need to format a string value in phone number format (555) 555-1212.  If the value is null, display nothing.</p>
  
  <p>For example, a table in my database has a phone number column and some values are NULL.</p>
  
  <p>I got a regex that formats the phone number fine.</p>
  
  <blockquote>
    <p>=System.Text.RegularExpressions.Regex.Replace(Fields!Phone.Value,
    "(\d{3})[ -.]<em>(\d{3})[ -.]</em>(\d{4})","($1) $2-$3")</p>
  </blockquote>
  
  <p>However if I do this:</p>
  
  <blockquote>
    <p>=IIf(Fields!Phone.Value is nothing, "", System.Text.RegularExpressions.Regex.Replace(Fields!Phone.Value,"(\d{3})[
    -.]<em>(\d{3})[ -.]</em>(\d{4})","($1) $2-$3"))</p>
  </blockquote>
  
  <p>Then it comes back with an error.  #ERROR is displayed on my report.  Can you use iif with a regex?  Is there another way?</p>