3

How can I convert [b]xxx[/b] to <strong>xxx</strong> using VB.NET Regex.Replace()?

Thanks.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
Curtis
  • 101,612
  • 66
  • 270
  • 352

2 Answers2

7

Just use a BBCode parser that someone else has written. It’s safer and more robust.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
6

Regex.Replace("\[b\](.*?)\[\/b\]", "<strong>$1</strong>") would do it

However, you don't need regex:

"[b]xxx[/b]".Replace("[b]","<strong>").Replace("[/b]","</strong>")

kͩeͣmͮpͥ ͩ
  • 7,783
  • 26
  • 40
  • Not using Regex could cause problems if an end [/b] isn't entered. And considering this content will be managed by the public, I'm sure they will forget :) – Curtis Nov 03 '10 at 14:22