首页 > 如何用sed正则删除文本中的tag?

如何用sed正则删除文本中的tag?

帮解释下这个正则

目的是删除文本文件中的tag

# cat html.txt
<b>This</b> is what <span style="text-decoration: underline;">I</span> meant. Understand?
$ sed 's/<[^>]*>//g' html.txt
This is what I meant. Understand?

<[^>]*>
分为三部分吧

  1. 匹配<

  2. 匹配不是>的内容, * 表明越多越好(贪婪匹配)

  3. 匹配>

综上就匹配到了tag了

【热门文章】
【热门文章】