正则表达式和替换为数字和文本
Regex and replacement with numbers and texts
在 epub 代码中,我有这段文字:
<span>Capitulo 1 - Apple is red</span>
<span>Capitulo 2 - Milk is white</span>
<span>Capitulo 3 - Weeds are green</span>
我需要将 "span" 标签替换为 "h1" 标签,并将 "capitulo" 的所有实例替换为 "chapter",并保留其余文本。我在口径上试过这个,没有运气:
Find: <span>Capitulo (/d+) * </span>
Replace: <h1>Chapter /1 * </h1>
我能做什么?
第二题:
如果我有这个文本:
<span>Capitulo 1 - apple is red, 5 chicas</span>
<span>Capitulo 2 - milk is white, 6 chicas</span>
<span>Capitulo 3 - weeds are green, 7 chicas</span>
我想获得:
<h1>Chapter1 - apple is red, 5 girls</h1>
<h2>Chapter2 - milk is white, 6 boys</h2>
<h3>Chapter3 - weeds are green, 7 men</h3>
我该如何进行?
您可以使用
查找: <span>Capitulo ([^<]*)</span>
替换:<h1>Chapter </h1>
查看 regex demo 和 Regulex 图:
([^<]*)
部分匹配除 <
之外的任何 0 个或多个字符,因为 [^<]
是 negated character class and the (...)
form a capturing group whose contents are accessible from the replacement pattern via backreferences(请参阅替换中的
)。
在 epub 代码中,我有这段文字:
<span>Capitulo 1 - Apple is red</span>
<span>Capitulo 2 - Milk is white</span>
<span>Capitulo 3 - Weeds are green</span>
我需要将 "span" 标签替换为 "h1" 标签,并将 "capitulo" 的所有实例替换为 "chapter",并保留其余文本。我在口径上试过这个,没有运气:
Find: <span>Capitulo (/d+) * </span>
Replace: <h1>Chapter /1 * </h1>
我能做什么?
第二题: 如果我有这个文本:
<span>Capitulo 1 - apple is red, 5 chicas</span>
<span>Capitulo 2 - milk is white, 6 chicas</span>
<span>Capitulo 3 - weeds are green, 7 chicas</span>
我想获得:
<h1>Chapter1 - apple is red, 5 girls</h1>
<h2>Chapter2 - milk is white, 6 boys</h2>
<h3>Chapter3 - weeds are green, 7 men</h3>
我该如何进行?
您可以使用
查找: <span>Capitulo ([^<]*)</span>
替换:<h1>Chapter </h1>
查看 regex demo 和 Regulex 图:
([^<]*)
部分匹配除 <
之外的任何 0 个或多个字符,因为 [^<]
是 negated character class and the (...)
form a capturing group whose contents are accessible from the replacement pattern via backreferences(请参阅替换中的 )。