使用正则表达式和崇高文本进行搜索和替换

时间:2021-06-13 16:50:06

I need to find all of the instances of the following pattern:

我需要找到以下模式的所有实例:

<(h1|p) class="veronaText hidden" (.*?)>(Answer:|)</(h1|p)>

and replace it to add an ID and an extra class. How can I replace it so that it keeps its current formatting and attributes (h1 or p, etc)?

并替换它以添加ID和额外的类。如何替换它以保持其当前格式和属性(h1或p等)?

1 个解决方案

#1


12  

<(h1|p) class="veronaText hidden" (.*?)>(Answer:|)</(h1|p)>

becomes

<$1 id="newID" class="veronaText hidden newClass" $2>$3</$4>

each $n represents a submatch within the main match, in the order they appear.

每个$ n代表主匹配中的子匹配,按它们出现的顺序排列。

#1


12  

<(h1|p) class="veronaText hidden" (.*?)>(Answer:|)</(h1|p)>

becomes

<$1 id="newID" class="veronaText hidden newClass" $2>$3</$4>

each $n represents a submatch within the main match, in the order they appear.

每个$ n代表主匹配中的子匹配,按它们出现的顺序排列。