我想删除单词class及其内容并保留其他标签而不影响段落中的单词:
<p class="Firstpara"><i>Let S be a regular surface, p</i> ∈ <i>S, and <span class="inline"/><img alt="" class="img_Owthpnkbckgrnd_jpg_w23h25_v-10px" src="../Images/img_Owthpnkbckgrnd.jpg" style=""/> = <img alt="" class="img_Owthpnkbckgrnd_jpg_w23h25_v-10px" src="../Images/img_Owthpnkbckgrnd.jpg" style=""/><sub>ϵ</sub></i>(<i>p</i>) <i>a normal neighborhood of p. Then every geodesic segment in <img alt="" class="img_Owthpnkbckgrnd_jpg_w23h25_v-10px" src="../Images/img_Owthpnkbckgrnd.jpg" style=""/> beginning at p is uniquely minimizing.</i></p>
我尝试使用此正则表达式并将其执行到记事本++:
找到:
(<img.*)(class=".*?")(.*?/>)
替换为:
$1$3
但未能保留段落中的字词。
答案 0 :(得分:0)
你可以试试这个:
(<img[^\/]*?)class="[^"]*"(.*?\/>)
const regex = /(<img[^\/]*?)class="[^"]*"(.*?\/>)/g;
const str = `<p class="Firstpara"><i>Let S be a regular surface, p</i> ∈ <i>S, and <span class="inline"/><img alt="" class="img_Owthpnkbckgrnd_jpg_w23h25_v-10px" src="../Images/img_Owthpnkbckgrnd.jpg" style=""/> = <img alt="" class="img_Owthpnkbckgrnd_jpg_w23h25_v-10px" src="../Images/img_Owthpnkbckgrnd.jpg" style=""/><sub>ϵ</sub></i>(<i>p</i>) <i>a normal neighborhood of p. Then every geodesic segment in <img alt="" class="img_Owthpnkbckgrnd_jpg_w23h25_v-10px" src="../Images/img_Owthpnkbckgrnd.jpg" style=""/> beginning at p is uniquely minimizing.</i></p>`;
const subst = `$1$2`;
const result = str.replace(regex, subst);
console.log(result);
&#13;
答案 1 :(得分:0)