匹配特定标签之间的字符串并转换为维基链接
Match strings between specific tags and convert to wikilinks
这个问题类似于我在这里问的另一个问题: 但我无法修改以执行新任务。 (解决方案应该适用于 EmEditor 或 Notepad++)
我需要匹配特定标签之间的文本,即<b class="b2">I have a lot of text, more text, some more text, text</b>
然后
- 在打开标签后仅将 第一个字符 转换为小写(代词 "I" 除外)
- 将逗号之间的内容转换为维基链接(并删除标签)。
我已经尝试 运行 一些正则表达式来通过多个步骤来接近这个,即
(<b class="b2">)(.)
[[\L
</b>
]]
(\[\[)(\w+), (\w+)(\]\])
]], [[
输入文字:
Any text <b class="b2">I make laugh</b>: Ar. and P. γέλωτα. Some more text <b class="b2">Delight</b>: P. and V. [[τέρπω]].
Any text <b class="b2">I amuse oneself, pass the time</b>: P. διάγειν.
Any text <b class="b2">It amuses oneself with, pass the time over, amuse</b>: Ar. and P.
预期输出:
Any text [[I make laugh]]: Ar. and P. γέλωτα. Some more text [[delight]]: P. and V. [[τέρπω]].
Any text [[I amuse oneself]], [[pass the time]]: P. διάγειν.
Any text [[it amuses oneself with]], [[pass the time over]], [[amuse]]: Ar. and P.
您应该分几步完成。
替换
<b class="b2">([^<]*)</b>
和
[[]]
将 <b>
标签转换为维基链接。
替换
(\[\[[^,\[\]]*?)(\s*),(\s*)
和
]], [[
将文本标记为维基链接。但是,可能需要 运行 多次,以替换所有逗号。参见 here。
替换
\[\[([A-Z])
和
[[\l
确保在 NPPP 中 select "Match case".
这会将 [[
之后的所有大写字母转换为小写字母。
替换
\[\[i(\s)
和
[[I
转换以恢复大写开头的代词。
这是一步解决方案:
- Ctrl+H
- 查找内容:
(?:<b class="b2">|\G(, (?=.*</b>)))(I )?([^,<]+)(?:</b>)?
- 替换为:
[[\l]]
- 选中环绕
- 检查正则表达式
- 取消勾选
. matches newline
- 全部替换
解释:
(?: # non capture group
<b class="b2"> # literally
| # OR
\G # restart from last match position
( # group 1, a comma and a space
, # a comma and a space
(?=.*</b>) # positive look ahead, make sure we have a closing tag after
) # end group 1
) # end group
(I )? # group 2, UPPER I and a space, optional
([^,<]+) # group 3, 1 or more any character that is not comma or less than
(?:</b>)? # optional end tag
替换:
# content og group 1 (i.e. comma & space)
[[ # double openning square bracket
# content of group 2, (i.e. "I ")
\l # lowercase the first letter of group 3 (i.e. all character until comma or end tag)
]] # double closing square bracket
给定示例的结果:
Any text [[I make laugh]]: Ar. and P. γέλωτα. Some more text [[delight]]: P. and V. [[τέρπω]].
Any text [[I amuse oneself]], [[pass the time]]: P. διάγειν.
Any text [[it amuses oneself with]], [[pass the time over]], [[amuse]]: Ar. and P.
[[be at ease]], v.: P. and V. ἡσυχάζειν, V. ἡσύχως ἔχειν.
屏幕截图:
这个问题类似于我在这里问的另一个问题:
我需要匹配特定标签之间的文本,即<b class="b2">I have a lot of text, more text, some more text, text</b>
然后
- 在打开标签后仅将 第一个字符 转换为小写(代词 "I" 除外)
- 将逗号之间的内容转换为维基链接(并删除标签)。
我已经尝试 运行 一些正则表达式来通过多个步骤来接近这个,即
(<b class="b2">)(.)
[[\L
</b>
]]
(\[\[)(\w+), (\w+)(\]\])
]], [[
输入文字:
Any text <b class="b2">I make laugh</b>: Ar. and P. γέλωτα. Some more text <b class="b2">Delight</b>: P. and V. [[τέρπω]].
Any text <b class="b2">I amuse oneself, pass the time</b>: P. διάγειν.
Any text <b class="b2">It amuses oneself with, pass the time over, amuse</b>: Ar. and P.
预期输出:
Any text [[I make laugh]]: Ar. and P. γέλωτα. Some more text [[delight]]: P. and V. [[τέρπω]].
Any text [[I amuse oneself]], [[pass the time]]: P. διάγειν.
Any text [[it amuses oneself with]], [[pass the time over]], [[amuse]]: Ar. and P.
您应该分几步完成。
替换
<b class="b2">([^<]*)</b>
和
[[]]
将 <b>
标签转换为维基链接。
替换
(\[\[[^,\[\]]*?)(\s*),(\s*)
和
]], [[
将文本标记为维基链接。但是,可能需要 运行 多次,以替换所有逗号。参见 here。
替换
\[\[([A-Z])
和
[[\l
确保在 NPPP 中 select "Match case".
这会将 [[
之后的所有大写字母转换为小写字母。
替换
\[\[i(\s)
和
[[I
转换以恢复大写开头的代词。
这是一步解决方案:
- Ctrl+H
- 查找内容:
(?:<b class="b2">|\G(, (?=.*</b>)))(I )?([^,<]+)(?:</b>)?
- 替换为:
[[\l]]
- 选中环绕
- 检查正则表达式
- 取消勾选
. matches newline
- 全部替换
解释:
(?: # non capture group
<b class="b2"> # literally
| # OR
\G # restart from last match position
( # group 1, a comma and a space
, # a comma and a space
(?=.*</b>) # positive look ahead, make sure we have a closing tag after
) # end group 1
) # end group
(I )? # group 2, UPPER I and a space, optional
([^,<]+) # group 3, 1 or more any character that is not comma or less than
(?:</b>)? # optional end tag
替换:
# content og group 1 (i.e. comma & space)
[[ # double openning square bracket
# content of group 2, (i.e. "I ")
\l # lowercase the first letter of group 3 (i.e. all character until comma or end tag)
]] # double closing square bracket
给定示例的结果:
Any text [[I make laugh]]: Ar. and P. γέλωτα. Some more text [[delight]]: P. and V. [[τέρπω]].
Any text [[I amuse oneself]], [[pass the time]]: P. διάγειν.
Any text [[it amuses oneself with]], [[pass the time over]], [[amuse]]: Ar. and P.
[[be at ease]], v.: P. and V. ἡσυχάζειν, V. ἡσύχως ἔχειν.
屏幕截图: