How can I remove HTML span tags with a Perl one liner?

Posted by yaya3 on Stack Overflow See other posts from Stack Overflow or by yaya3
Published on 2010-05-26T11:24:04Z Indexed on 2010/05/27 5:11 UTC
Read the original article Hit count: 312

Filed under:
|
|
|

I want to perform the following vim substitution as a one-liner in the terminal with Perl. I would prefer to allow for any occurences of whitespace or newlines, rather than explicitly catering for them as I am below.

%s/blockDontForget">\n*\s*<p><span><a\(.*\)<\/span>/blockDontForget"><p><a\1/g 

I've tried this:

perl -pi -e 's/blockDontForget"><p><span><a(.*)<\/span>/blockDontForget"><p><a$1/msg'

I presume I am misinterpreting the flags. Where am I going wrong? Thanks.

EDIT:

The above example is to strip the spans out of the following html:

<div class="block blockDontForget">
    <p><span><a href="../../../foo/bar/x/x.html">Lorem Ipsum</a></span></p>      

EDIT:

It's just the <span>'s and </span>'s that are inbetween <p> and <a> from the "blockDontForget" class
</div> that I want to remove (there are lots or these blockDontForget divs with spans inside anchors that I want to keep).

© Stack Overflow or respective owner

Related posts about html

Related posts about regex