如何使用grep匹配HTML特定标记与属性之间的内容? [英] How to match content between HTML specific tags with attribute using grep?

查看:94
本文介绍了如何使用grep匹配HTML特定标记与属性之间的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想匹配标记< div class =Message> 中包含的文本,我应该使用命令 grep c $ c>和它的结束标记< / div> 在HTML文件中?

Which regular expression should I use with the command grep if I wanted to match the text contained within the tag <div class="Message"> and its closing tag </div> in an HTML file?

推荐答案

grep -oP '(?<=<div class="Message"> ).*?(?= </div>)' file

如果您的代码跨越多行,请尝试:

If your tags span multiple lines, try:

< file tr -d '\n' | grep -oP '(?<=<div class="Message"> ).*?(?= </div>)'

这篇关于如何使用grep匹配HTML特定标记与属性之间的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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