Python 正则表达式替换所有的为

时间:2022-01-24 05:45:09
1. Replace all <b> with <strong>, preserving any existing attributes
Match:
<(/?)b\b((?:[^>"']| "[^"]*"| '[^']*')*)>

Replace:
<\1strong\2>

eg.
<b fdjfkjdk>inikkk</b fdjkfjk>
====>
<strong fdjfkjdk>inikkk</strong fdjkfjk>

2. Replace all <b> with <strong>, discarding any existing attributes
Match:
<(/?)b\b((?:[^>"']| "[^"]*"| '[^']*')*)>

Replace:
<\1strong\2>

eg.
<b fdjfkjdk>inikkk</b fdjkfjk>
====>
<strong>inikkk</strong>

3. Replace a list of tags (<b> <i> <em> <big>) with <strong>, preserving any existing attributes
Match:
<(/?)([bi]|em|big)\b((?:[^>"']| "[^"]*"| '[^']*')*)>

Replace:
<\1strong\3>

eg.
<b fdjfkjdk>inikkk</b fdjkfjk>
<i fff>nihao</i nihao>
<em ff>nihao</em nihao>
<big ff>nihao</big nihao>
=====>
<strong fdjfkjdk>inikkk</strong fdjkfjk>
<strong fff>nihao</strong nihao>
<strong ff>nihao</strong nihao>
<strong ff>nihao</strong nihao>

4. Replace a list of tags (<b> <i> <em> <big>) with <strong>, discarding any existing attributes
Match:
<(/?)([bi]|em|big)\b((?:[^>"']| "[^"]*"| '[^']*')*)>

Replace:
<\1strong>

eg.
<b fdjfkjdk>inikkk</b fdjkfjk>
<i fff>nihao</i nihao>
<em ff>nihao</em nihao>
<big ff>nihao</big nihao>
=====>
<strong>inikkk</strong>
<strong>nihao</strong>
<strong>nihao</strong>
<strong>nihao</strong>