Scala - 从字符串中去除所有 html 标签,除了链接 [英] Scala - Strip all html tags from string except links
本文介绍了Scala - 从字符串中去除所有 html 标签,除了链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用在 Scala 中的这个线程上找到的正则表达式模式:
I'm trying to use a regex pattern found on this thread in scala:
value.replaceAll("s/<(?!\/?a(?=>|\s.*>))\/?.*?>//g", "")
这给了我几个编译错误,都是无效的转义字符"
This gives me several compilation errors, all being "Invalid escape character"
我需要做什么才能让 Scala 对此感到满意?
What do I need to do to make scala happy with this?
提前致谢
编辑
使用以下内容进行操作,无需在正则表达式字符串的开头和结尾使用 s/或//g.
Got it working with the following, no need for the s/ or //g at beginning and end of regex string.
value.replaceAll("""<(?!\/?a(?=>|\s.*>))\/?.*?>""", "")
推荐答案
尝试逐字字符串文字 value.replaceAll("""<(?!\/?a(?=>|\s.*>))\/?.*?>""", "")
处理正则表达式时抑制 Scala 的字符串转义.
Try verbatim string literal value.replaceAll("""<(?!\/?a(?=>|\s.*>))\/?.*?>""", "")
when dealing with regex to suppress Scala's string escaping.
这篇关于Scala - 从字符串中去除所有 html 标签,除了链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文