3.3. Notepad++中正则表达式用法举例

例 3.1. Notepad++中用正则表达式实现字符串替换

用如下写法:

查找目标 :

images/env_var/win/(\w+)\.jpg

替换为(P):

images/env_var/win/\1\.png

可以实现,将:


<informalfigure>
    <mediaobject>
        <imageobject role="html"><imagedata fileref="images/env_var/win/right_click_then_property.jpg" align="left" scalefit="0" width="100%"/></imageobject>
        <imageobject role="fo"><imagedata fileref="images/env_var/win/right_click_then_property.jpg" align="center" scalefit="1" width="100%"/></imageobject>
    </mediaobject>
</informalfigure>
......
<informalfigure>
    <mediaobject>
        <imageobject role="html"><imagedata fileref="images/env_var/win/advance_enviroment.jpg" align="left" scalefit="0" width="100%"/></imageobject>
        <imageobject role="fo"><imagedata fileref="images/env_var/win/advance_enviroment.jpg" align="center" scalefit="1" width="100%"/></imageobject>
    </mediaobject>
</informalfigure>

        

替换为所需要的结果:


<informalfigure>
    <mediaobject>
        <imageobject role="html"><imagedata fileref="images/env_var/win/right_click_then_property.png" align="left" scalefit="0" width="100%"/></imageobject>
        <imageobject role="fo"><imagedata fileref="images/env_var/win/right_click_then_property.png" align="center" scalefit="1" width="100%"/></imageobject>
    </mediaobject>
</informalfigure>
......
<informalfigure>
    <mediaobject>
        <imageobject role="html"><imagedata fileref="images/env_var/win/advance_enviroment.png" align="left" scalefit="0" width="100%"/></imageobject>
        <imageobject role="fo"><imagedata fileref="images/env_var/win/advance_enviroment.png" align="center" scalefit="1" width="100%"/></imageobject>
    </mediaobject>
</informalfigure>

        



更详细的解释,可以参考:Notepad++的正则表达式替换