Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Regex Expression to remove RTF tags Expand / Collapse
Author
Message
Posted Friday, March 8, 2013 6:25 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 2:25 AM
Points: 20, Visits: 332
Hi There,

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\deff0ouicompat\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
)

Thanks & Regards,
Post #1428549
Posted Wednesday, March 13, 2013 12:03 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 2:25 AM
Points: 20, Visits: 332
Any suggestions?
Post #1430554
Posted Wednesday, March 13, 2013 1:56 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:35 PM
Points: 12,887, Visits: 31,832
Sel what I've done myself is to create a CLR function that returns RTF2Text, or vice versa;
that's the best way i know of, because the RichTextBox from windows.forms handles ALL the rules you might miss with more complex RTF documents, by just doing string manipulation.

If it's an option, i can post an example project.


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1430615
Posted Wednesday, March 13, 2013 4:16 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 2:25 AM
Points: 20, Visits: 332
Lowell (3/13/2013)
Sel what I've done myself is to create a CLR function that returns RTF2Text, or vice versa;
that's the best way i know of, because the RichTextBox from windows.forms handles ALL the rules you might miss with more complex RTF documents, by just doing string manipulation.

If it's an option, i can post an example project.


First of all thanks for your response. can you please give me an example project? Secondly how do I accommodate to my project your project? Please clarify.

My project is here : https://skydrive.live.com/#cid=2FA6294B3E381151&id=2FA6294B3E381151!128

Thanks,
Post #1430664
Posted Friday, March 15, 2013 1:35 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 2:25 AM
Points: 20, Visits: 332
Any suggestions ?
Post #1431718
Posted Friday, April 19, 2013 1:23 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, April 19, 2013 1:25 PM
Points: 1, Visits: 2
I'm assuming this reply is too late for your use but in case anyone else needs...

This works well for me:

\\\w+|\{.*?\}|}

Post #1444584
Posted Sunday, April 21, 2013 7:25 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 2:25 AM
Points: 20, Visits: 332
erik 25824 (4/19/2013)
I'm assuming this reply is too late for your use but in case anyone else needs...

This works well for me:

\\\w+|\{.*?\}|}



Like you said , I've changed regex expression. But I've having same problem. Can you send me the report file which is rdl extension that you are using?

Regards and thanks,
Post #1444794
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse