我想要一个正则表达式,它不会返回包含在以 <!--
开头和/或以 -->
结尾的 html 注释中的字符串
我目前只用它来检查它是否从 <!--
开始并且具有等于 hello
的文本:
^(?!<!--).*hello.*$
它似乎工作正常,但是当我测试多行示例时,它根本不返回任何匹配项。
这是我测试的内容:
hello there
<!- hello there -->
<!-- hello there -->
所以我希望前两个将作为匹配项返回:
hello there
<!- hello there -->
但是这个 Regex 测试没有返回结果,除非我只给出了第一行 (hello there
):
regexr.com/5t1ng
帮助任何人??如果以 -->
结尾,如何进行正则表达式检查以排除匹配?
也就是说,我希望:
<!-- hello
- 不应该匹配hello -->
- 不应该匹配<-- hello -->
- 不应该匹配<!- hello
- 应该匹配<-- hello
- 应该匹配<-- hello ->
应该匹配谢谢!