Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala - Strip all html tags from string except links

Tags:

regex

scala

I'm trying to use a regex pattern found on this thread in scala:

Strip all HTML tags except links

value.replaceAll("s/<(?!\/?a(?=>|\s.*>))\/?.*?>//g", "")

This gives me several compilation errors, all being "Invalid escape character"

What do I need to do to make scala happy with this?

Thanks in advance

EDIT

Got it working with the following, no need for the s/ or //g at beginning and end of regex string.

value.replaceAll("""<(?!\/?a(?=>|\s.*>))\/?.*?>""", "")
like image 311
jahilldev Avatar asked Oct 14 '11 14:10

jahilldev


1 Answers

Try verbatim string literal value.replaceAll("""<(?!\/?a(?=>|\s.*>))\/?.*?>""", "") when dealing with regex to suppress Scala's string escaping.

like image 199
Eugene Yokota Avatar answered Sep 25 '22 20:09

Eugene Yokota