正则表达式查找 html 注释但不是 ie 仅注释 [英] Regex to find html comment but not ie only comment

查看:37
本文介绍了正则表达式查找 html 注释但不是 ie 仅注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想使用正则表达式匹配有效的 HTML 注释.我在 stackoverflow 上看到了很多问题,但没有人回答这个问题.允许匹配的模式

I want to match valid HTML comment only using regex. I have seen many questions on stackoverflow but no one answer this. Patterns allowed to match

<!-- some comments 1 -->
<!-- 1.91 -->
<!--
//-->
<!-- -->

但不是这些仅限 IE 的评论

But not these IE-only comments

<!--[if IE]> <![endif]-->
<!--[if !IE]><!-->  <!--<![endif]-->
<!--[if IE 6]> <![endif]-->

我认为如果在 <!-- 之后找到第一个字符,则可以通过 '[' 的帮助来完成它返回false.您可以通过任何方式提供自己的解决方案.对于 php 仅使用 preg_replace

What I think that it can be done by taking help of '[' if it is found as first character after <!-- it returns false. any way you can give your own solution. for php only to use preg_replace

推荐答案

我真的不建议您使用正则表达式来执行此操作,但是如果您坚持,这里有一个基本的正则表达式:http://regex101.com/r/wI2kF7

I really don't recommend you do this using regex, but if you insist, here is a basic regular expression: http://regex101.com/r/wI2kF7

带锚标签:http://regex101.com/r/tC9xH4

祝你好运.

这篇关于正则表达式查找 html 注释但不是 ie 仅注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆