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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With