我需要一个正则表达式来从字符串中去除单行注释,但是保持URL不变。代码应与东西合作是这样的:
PHP:正则表达式来查找以双斜杠开头的注释//
//Some Comment on http://bobobo.com where bla < 5
<script type="text/javascript" src="http://bububu.com"></script>
<script type='text/javascript' src='http://bababa.com'></script>
编辑:当然,我不使用的注释,在HTML文件中。正确的例子将是
<script type="text/javascript">
//Some Comment on http://bobobo.com where bla < 5
</script>
<script type="text/javascript" src="http://bububu.com"></script>
<script type='text/javascript' src='http://bababa.com'></script>
我不好,抱歉误导。
一个可能的解决方案应该找到 “//上http://bobobo.com其中BLA < 5的一些评论”,而不是 “//bububu.com”>”和 “//bababa.com”>“。
感谢任何提示...
Do ** NOT **使用正则表达式来处理html:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags –
@Marc B:剥离出单行评论会没事的。 – Tomalak
@Tomalak:也许吧,但是当你试图找出一个特定的评论实际上是一个评论,或者一个埋在一个属性中的网址,或者实际上是一个纯文本网址。 –