Reputation: 2173
In my huge xml file there are some code-lines which are commented.
I just want to remove them with regex, without touching document comment which contains "*".
I tried find (?s)<!--.*?-->
and replace with null, but it removes all xml comments.
Below is my sample xml file:
<?xml version="1.0"?>
<!--
/**
* Company_Module extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category Perception
* @package Company_Module
* @copyright Copyright (c) 2008 Perception LLC
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* @category Perception
* @package Company_Module
* @author Boris (Moshe) Gurevich <[email protected]>
*/
-->
<config>
<modules>
<Company_Module>
<version>0.2.6</version>
</Company_Module>
</modules>
<global>
<models>
<pstorelocator>
<class>Company_Module_Model</class>
<resourceModel>pstorelocator_mysql4</resourceModel>
</pstorelocator>
<pstorelocator_mysql4>
<class>Company_Module_Model_Mysql4</class>
<entities>
<location>
<table>pstorelocator_location</table>
</location>
</entities>
</pstorelocator_mysql4>
</models>
<resources>
<pstorelocator_setup>
<setup>
<module>Company_Module</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</pstorelocator_setup>
<pstorelocator_write>
<connection>
<use>core_write</use>
</connection>
</pstorelocator_write>
<pstorelocator_read>
<connection>
<use>core_read</use>
</connection>
</pstorelocator_read>
</resources>
<helpers>
<pstorelocator><class>Company_Module_Helper</class></pstorelocator>
</helpers>
<blocks>
<pstorelocator><class>Company_Module_Block</class></pstorelocator>
</blocks>
<pstorelocator>
<private_fields></private_fields>
</pstorelocator>
</global>
<frontend>
<routers>
<pstorelocator>
<use>standard</use>
<args>
<module>Company_Module</module>
<frontName>pstorelocator</frontName>
</args>
</pstorelocator>
</routers>
<translate>
<modules>
<Company_Module>
<files>
<default>Company_Module.csv</default>
</files>
</Company_Module>
</modules>
</translate>
<layout>
<updates>
<pstorelocator module="Company_Module">
<file>pstorelocator.xml</file>
</pstorelocator>
</updates>
</layout>
</frontend>
<admin>
<routers>
<pstorelocatoradmin>
<use>admin</use>
<args>
<module>Company_Module</module>
<frontName>pstorelocatoradmin</frontName>
</args>
</pstorelocatoradmin>
</routers>
</admin>
<adminhtml>
<menu>
<perception>
<title>Perception</title>
<sort_order>71</sort_order>
<children>
<!--<pstorelocator translate="title" module="pstorelocator">
<title>Advance Store Locator</title>
<sort_order>3</sort_order>
<action>pstorelocatoradmin/adminhtml_location/</action>
</pstorelocator>-->
</children>
</perception>
</menu>
<acl>
<resources>
<admin>
<children>
<pstorelocator>
<title>Perception</title>
<sort_order>71</sort_order>
<children>
<!--<pstorelocator translate="title" module="pstorelocator">
<title>Advance Store Locator</title>
</pstorelocator>-->
</children>
</pstorelocator>
<system>
<children>
<config>
<children>
<pstorelocator>
<title>Advance Store Locator</title>
</pstorelocator>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
<translate>
<!--<modules>
<Company_Module>
<files>
<default>Company_Module.csv</default>
</files>
</Company_Module>
</modules>-->
</translate>
</adminhtml>
<default>
<pstorelocator>
<general>
<google_geo_url><![CDATA[https://maps.google.com/maps/geo]]></google_geo_url>
<!--<show_search>1</show_search>-->
<show_map>0</show_map>
</general>
</pstorelocator>
</default>
</config>
Upvotes: 1
Views: 82
Reputation: 89285
Building on your regex, you can replace .
which match any character within XML comment, to [^*]
which will match any character except literal char *
:
(?s)<!--[^*]*?-->
Upvotes: 2