Dies ist ein Beispielcode aus einem Scalabuch. Dieses Objekt verfügt über eine Methode, die alle HTML-Tags in einer gegebenen Zeichenfolge entfernt. Aber aus Grund, entfernt es den gesamten String-Inhalt nicht nur HTML-Tags. Darf ich wissen warum?Warum funktioniert dieser einfache reguläre Ausdruck nicht?
object HtmlUtils {
def removeMarkup(input: String) = {
input.replaceAll("""</?\w[^>]*>""","")
input.replaceAll("<.*>","")
}
}
val ahtmlText = "<html><body><h1>Introduction</h1></body></html>"
val anewhtmlText = HtmlUtils.removeMarkup(ahtmlText)
println(anewhtmlText)
println(s"Before removing html tags, the string was $ahtmlText and after rmoving html tags the string became $anewhtmlText")