<p>I'd like to take some RTF input and clean it to remove all RTF formatting except \ul \b \i to paste it into Word with minor format information.</p>

<p>The command used to paste into Word will be something like:
oWord.ActiveDocument.ActiveWindow.Selection.PasteAndFormat(0) (with some RTF text already in the Clipboard)</p>

<pre><code>{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}
{\colortbl ;\red255\green255\blue140;}
\viewkind4\uc1\pard\highlight1\lang3084\f0\fs18 The company is a global leader in responsible tourism and was \ul the first major hotel chain in North America\ulnone  to embrace environmental stewardship within its daily operations\highlight0\par
</code></pre>

<p>Do you have any idea on how I can clean up the RTF safely with some regular expressions or something? I am using VB.NET to do the processing but any .NET language sample will do.</p>

[{'answer_id': 20498, 'author': 'Chris Miller', 'author_id': 206, 'author_profile': 'https://Stackoverflow.com/users/206', 'pm_score': 2, 'selected': False, 'text': '<p>You can strip out the tags with regular expressions.  Just make sure that your expressions will not filter tags that were actually text.  If the text had "\\b" in the body of text, it would appear as \\b in the RTF stream.   In other words, you would match on "\\b" but not "\\b".</p>\n\n<p>You could probably take a short cut and filter out the header RTF tags.  Look for the first occurrence of "\\viewkind4" in the input.  Then read ahead to the first space character.  You would remove all of the characters from the start of the text up to and including that space character.  That would strip out the RTF header information (fonts, colors, etc).</p>\n'}, {'answer_id': 20628, 'author': 'Nick', 'author_id': 1490, 'author_profile': 'https://Stackoverflow.com/users/1490', 'pm_score': 4, 'selected': True, 'text': '<p>I would use a hidden RichTextBox, set the Rtf member, then retrieve the Text member to sanitize the RTF in a well-supported way.  Then I would use manually inject the desired formatting afterwards.</p>\n'}, {'answer_id': 20708, 'author': 'Martin', 'author_id': 770, 'author_profile': 'https://Stackoverflow.com/users/770', 'pm_score': 3, 'selected': False, 'text': '<p>I\'d do something like the following:</p>\n\n<pre><code>Dim unformatedtext As String\n\nsomeRTFtext = Replace(someRTFtext, "\\ul", "[ul]")\nsomeRTFtext = Replace(someRTFtext, "\\b", "[b]")\nsomeRTFtext = Replace(someRTFtext, "\\i", "[i]")\n\nDim RTFConvert As RichTextBox = New RichTextBox\nRTFConvert.Rtf = someRTFtext\nunformatedtext = RTFConvert.Text\n\nunformatedtext = Replace(unformatedtext, "[ul]", "\\ul")\nunformatedtext = Replace(unformatedtext, "[b]", "\\b")\nunformatedtext = Replace(unformatedtext, "[i]", "\\i")\n\nClipboard.SetText(unformatedtext)\n\noWord.ActiveDocument.ActiveWindow.Selection.PasteAndFormat(0)\n</code></pre>\n'}, {'answer_id': 10941969, 'author': 'Toby Holland', 'author_id': 1367075, 'author_profile': 'https://Stackoverflow.com/users/1367075', 'pm_score': 1, 'selected': False, 'text': '<p>Regex it, it wont parse absolutely everything correctly (tables for example) but does the job in most cases.</p>\n\n<pre><code>string unformatted = Regex.Replace(rtfString, @"\\{\\*?\\\\[^{}]+}|[{}]|\\\\\\n?[A-Za-z]+\\n?(?:-?\\d+)?[ ]?", "");\n</code></pre>\n\n<p>Magic =)</p>\n'}]
['https://Stackoverflow.com/questions/20450', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1508/']