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