views:

37

answers:

1

I need to get a list of tags in a text, make their contents bold, and remove them. Can't figure out how to make it.

E.g. with the following input:

foo [b]bar[/b]

The result should be:

foo bar

I use the following code to extract the tags:

 Dim matches = Regex.Matches(OriginalRich.Text, String.Format("(\[{0}\])(.*?)(\[/{0}\])", tag), RegexOptions.IgnoreCase Or RegexOptions.Compiled)

Any help would be appreciated.

A: 

You could try doing it in two steps: apply the formatting to the whole match including the tags, then make another pass to remove the tags. But if you're doing all this in the same control, I'd say that's your real problem.

I would use a plain TextBox for the input, with a non-editable RichTextBox to preview the result. Basically, the same approach that's used here at StackOverflow (but with a different toolset).

Alan Moore