找到一些字符串并使用notepad ++正则表达式替换另一个字符串

时间:2014-05-28 09:34:46

标签: html regex replace find notepad++

在多个Php Web Pages中,我想为现有(并且已存在的)html code添加一些额外的html code。例如,我有:

<a class="fix" name="P169336">&nbsp;</a>

我想使用此示例替换位于同一html code其他位置的另一个Web Page。例如,我有:

class="hyperlink">Alessandro Marinuzzi</a></td></tr>

所以使用第一个(示例)添加到第二个(示例),如下所示:

class="hyperlink">Alessandro Marinuzzi</a><br /><br /><div class="srtgs" id="rt_169336"></div></td></tr>

来自rt_169336的地方:

<a class="fix" name="P169336">&nbsp;</a>

每个Web Page都有一个:

<a class="fix" name="PXXXXXX">&nbsp;</a>

你可以找到......

<a class="fix" name="P169336">&nbsp;</a>

<a class="fix" name="P167223">&nbsp;</a>

或为Web Page ...

更改的其他其他数字

我希望使用notepad++ regular expressions的功能进行此替换。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

搜索

(<A CLASS="fix" NAME="P)(\d+)(">&nbsp;</A>)(.*?)(Marinuzzi</A>)(</TD></TR>)

,其中

  • (<A CLASS="fix" NAME="P)第1组,数字前的数据
  • (\d+)第2组,数字
  • (">&nbsp;</A>)第3组,数字后的数据
  • (.*?)第4组,搜索和替换部分之间的数据
  • (Marinuzzi</A>)第5组,替换前的数据
  • (</TD></TR>)第6组,替换后的数据

并替换为

\1\2\3\4\5<BR><BR><DIV CLASS="srtgs" ID="rt_\2"></DIV>\6

,其中

  • \1\2\3\4\5重新插入组1-5
  • <BR><BR><DIV CLASS="srtgs" ID="rt_\2"></DIV>在第2组插入新内容
  • \6重新插入第6组

搜索模式必须为Regular expression. matches newline已启用。

请注意,此代码假定搜索元素位于目标元素之前。

相关问题