Regular Expression: back references

Posted by sixtyfootersdude on Stack Overflow See other posts from Stack Overflow or by sixtyfootersdude
Published on 2010-04-05T16:28:17Z Indexed on 2010/04/05 16:33 UTC
Read the original article Hit count: 295

Filed under:
|
|
sed 's/^\(\h*\)\(.*\)$/\1<!-- \2 -->/' web.xml

I think that this should take this xml:

<a>
  <d>
    bla
  </d>
</a>

And turn it into:

<!-- <a> -->
  <!-- <d> -->
    <!-- bla -->
  <!-- </d> -->
<!-- </a> -->

But what is doing is this:

<!-- <a> -->
<!--   <d> -->
<!--     bla -->
<!--   </d> -->
<!-- </a> -->

© Stack Overflow or respective owner

Related posts about sed

Related posts about regex