Regular Expression to Strip HTML Tags

ObjectScript, Caché

I want to use the Regex Matcher to strip HTML tags, but I get a REGEX error. Can anyone explain what I'm doing wrong?

set htmlSnippet = "<h1>Hello</h1>"
set regex = ##class(%Regex.Matcher).%New()
set regex.Text = htmlSnippet
set regex.Pattern = "<[^>]*>"
set plainText = regex.ReplaceAll(" ")
write !,plainText

  • 0
  • 0
  • 506
  • 0
  • 1

Answers

Add init parameters:

set htmlSnippet = "<h1>Hello</h1>"
set regex = ##class(%Regex.Matcher).%New("<[^>]*>", htmlSnippet)
set plainText = regex.ReplaceAll(" ")
write !,plainText