How To Match Content Between Tags Without Regex

左心房为你撑大大i 提交于 2019-12-11 15:33:19

问题


I have read the following post about How to match content between HTML specific tags with attribute using grep?. However, when I use the code derived from that page, I'm unable to match the content. I keep getting a blank output.

Here's the code I'm using:

grep -oP '(?<=<div class="tag"> ).*?(?= </tag>)' file1.txt

I've ensured that all the line endings are in linux (LF).

Here's file1.txt:

        <div class="tag">

            <p>hello world!</p>
        </tag><!-- .end-section -->

I would want the output:

        <div class="tag">

            <p>hello world!</p>
        </tag>

Does anyone know why I can't match the content between these lines? I have tried everything that I can think of. Your insight and support is highly appreciated.

来源:https://stackoverflow.com/questions/46866839/how-to-match-content-between-tags-without-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!