Search code examples
parsingscalastringliftstrip-tags

Strip HTML tags from Scala String


I am developing web app using Scala and Lift framework. I have record in DB which contains html perex of page

<b>Hi all, this is perex</b>

And in one scenario I need to print to user this perex, but without html tags.

Hi all, this is perex

It is possible to do this in Scala? Because I tried to look with Google, but with no success.

thanks for all replies.


Solution

  • If the string is valid XML then you can use:

    scala.xml.XML.loadString("<b>Hi all, this is parex</b>").text

    If it's not valid XML, then you can use scala.util.matching.Regex or an HTML parsing library like http://jsoup.org/