【发布时间】:2021-07-23 23:27:12
【问题描述】:
我有以下markdown文件,其中包含一系列HTML样式的cmets:
hello this is my file
<!-- START COMMENT -->
<!-- END COMMENT -->
the rest of the file
有时评论标签是空的,而其他时候它们里面会有内容:
hello this is my file
<!-- START COMMENT -->
some
content
here
<!-- END COMMENT -->
the rest of the file
我正在尝试替换标签的内容,但保持标签完好无损,以便它们仍然围绕内容。我尝试了以下正则表达式,但它似乎也替换了标签,这不是我需要的:
data = data.replace(
/<!-- START COMMENT -->[\s\S]*?<!-- END COMMENT -->/g,
generatePlaceholders(response)
)
如何调整我的正则表达式,使其仅替换内容?
【问题讨论】:
标签: javascript regex