The other day I needed to display an RTF text stored in a database in a SQL Reporting Services report…  After doing some research, the team came to a conclusion that there is no easy way to do that, especially given the time we had left on the project.  The decision was made to strip-off the RTF formatting characters and display it as plain text.  A co-worker of mine, Scott Jennings, a.k.a. the “RegEx-Man”, came up with the following expression to do the job:

Regex.Replace(Regex.Match(rtf, @"\x5cviewkind4[^ ]*(.+)\x5cpar").Groups[1].Value, @"[\n\r\f]|(\x5cpar)|(\x5c[a-zA-Z0-9]+)", "");

 

We’ve done some preliminary testing and it looks good so far…  However, if you come up with any improvements, kindly post them to this blog so all could benefit.