Regex Expression to remove RTF tags


  • I have a file that I get from pulling out values from a Microsoft Lync 2013 conversation that has RTF formatting tags. An example file would be like:

    Here is my file:

          {\rtf1\fbidis\ansi\ansicpg1254\deff0\nouicompat\deflang1055{\fonttbl{\f0\fnil\fcharset162 Segoe UI;}{\f1\fnil\fcharset238 Segoe UI;}{\f2\fnil Segoe UI;}}
          {\colortbl ;\red0\green0\blue0;}
          {\*\generator Riched20 15.0.4420}{\*\mmathPr\mwrapIndent1440 }\viewkind4\uc1
          \pard\cf1\embo\f0\fs20 emaillerini\embo0  \embo al \embo0  \f2\par
          {\*\lyncflags rtf=1}}

    I want to remove RTF tags and  and just pull out the text of the conversation. So the result of my function should be:

        emaillerini al

    BTW, I been using Microsoft SQL Server Report Builder for that. I have a expression like below and but it's not working.

         =SWITCH(Fields!ContentType.Value = "text/rtf",Code.ConvertRtfToTextRegex(Fields!Body.Value),
         Fields!ContentType.Value = "text/plain",Fields!Body.Value,
         Fields!ContentType.Value = "text/html",System.Text.RegularExpressions.Regex.Replace(Fields!Body.Value, "\<[^\>]+\>", ""),
         Fields!ContentType.Value <> "", Fields!Body.Value


    Sunday, March 03, 2013 5:02 PM


All replies