我必须替换 GWT 中两个字符串之间的所有内容。例如,
在字符串"<script> something ... start .... </script>"
中我想替换 start
之间的所有内容和</script>
.
我用过theString.replaceAll("start.*?</script>", "")
但什么也没发生。
我在 Java 程序中尝试了这个,它替换了 start
中的所有内容但这在 GWT 客户端代码中不会发生。
我们如何实现这一目标?
最佳答案
你可以尝试:
theString = theString.replaceAll("(?s)start.*?</script>", "");
由于 Javascript 代码段中的输入可能存在新行,因此 (?s)
也会使 DOT 匹配新行。
等效的 Javascript 正则表达式:
theString = theString.replace(/start[\s\S]*?<\/script>/, "");
关于java - GWT String.replace 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21989283/