in reply to Regular Expression to replace & in XML

This would update the files (it OVERWRITES them, so be careful)

perl -pi -e 's/&#(?!\d+;)/ /g'  myfile.xml

This would

1. Find something that has &# but not &#digit;
2. replace it with a space.

Replies are listed 'Best First'.
Re^2: Regular Expression to replace & in XML
by denzil_cactus (Sexton) on Nov 20, 2016 at 17:31 UTC
    Hi there,

    thanks for the suggestion but this solution does not work with 'sed' command as I mentioned in my question.
    If the XML has the character '&#','&' etc then the XML file can not be opened and hence I am trying to use 'sed' command.

    Below are link for XML special character translation for reference
    http://xml.silmaril.ie/specials.html
    https://www.dvteclipse.com/documentation/svlinter/How_to_use_special_characters_in_XML.3F.html

    Could you please help using 'sed' command?
        Thanks Hauke

        Completely understand this is a website for perl and I was struggling to implement
        the logic inside my application and it worked.
        Thanks a lot Monks!!