删除不包含星号字符的xml注释

时间:2016-02-05 05:43:57

标签: xml replace comments editor geany

在我的巨大xml文件中有一些注释的代码行。

我只想用正则表达式删除它们,而不触及包含“*”的文档注释。

我尝试查找(?s)<!--.*?-->并替换为null,但它会删除所有xml注释。

以下是我的示例xml文件:

<?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 <moshe@Perception.com>
 */
-->
<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>

1 个答案:

答案 0 :(得分:2)

在您的正则表达式的基础上,您可以将符合XML注释中任何字符的.替换为[^*],它将匹配除文字字符*之外的任何字符

(?s)<!--[^*]*?-->