使用regexp删除html注释标签 [英] delete html comment tags using regexp

查看:91
本文介绍了使用regexp删除html注释标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

This is how my text (html) file looks like
    <!--
     |                                |
     |  This is a dummy comment       |
     |      please delete me          |
     |         asap                   |
     |                                |
      ________________________________
     | -->

    this is another line 
    in this long dummy html file...
    please do not delete me

我正在尝试使用sed删除评论:

I'm trying to delete the comment using sed :

cat file.html | sed 's/.*<!--\(.*\)-->.*//g'

它不起作用:(我在做什么错了?

It doesn't work :( What am I doing wrong?

非常感谢您的帮助!

推荐答案

patrickmdnet具有正确的答案.这是使用扩展正则表达式的一行:

patrickmdnet has the correct answer. Here it is on one line using extended regex:

cat file.html | sed -e :a -re 's/<!--.*?-->//g;/<!--/N;//ba'

这里是学习sed的好资源.此sed是单线#92的改编

Here is a good resource for learning more about sed. This sed is an adaptation of one-liner #92

http://www.catonmat.net/blog /sed-one-liners-explained-part-三/

这篇关于使用regexp删除html注释标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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