Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 774
kajo Avatar asked Mar 22 '11 14:03

kajo


1 Answers

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/

like image 62
Erick Fleming Avatar answered Oct 28 '22 08:10

Erick Fleming