Notepad++ 和正则表达式 - 如何在两个特定字符串之间命名大小写字符串?

Notepad++ and regex - how to title case string between two particular strings?

我在一个文件中有数百个 bib 引用,它们具有以下语法:

@article{tabata1999precise,
  title={Precise synthesis of monosubstituted polyacetylenes using Rh complex catalysts. 
Control of solid structure and $\pi$-conjugation length},
  author={Tabata, Masayoshi and Sone, Takeyuchi and Sadahiro, Yoshikazu},
  journal={Macromolecular chemistry and physics},
  volume={200},
  number={2},
  pages={265--282},
  year={1999},
  publisher={Wiley Online Library}
}

我想在 Notepad++ 中使用正则表达式对期刊名称进行标题大小写(也称为 Proper Case)。例如,从 Macromolecular chemistry and physicsMacromolecular Chemistry and Physics

我能够使用以下方法找到所有实例:

(?<=journal\=\{).*?(?=\})

但我无法通过“编辑”>“将大小写转换为”更改大小写。显然它不能找到所有,我必须一个一个地去。

接下来,我尝试录制并 运行 设置一个宏,但是当我尝试 运行 时 Notepad++ 会无限期地挂起(选择 运行 直到文件末尾)。

所以我的问题是:有人知道我可以用来更改大小写的替换正则表达式语法吗?理想情况下,我也想使用“|”排除特定单词,例如“of”、“an”、“the”等。我尝试使用提供的一些示例 here,但我无法将其整合到我的 look-aheads.

提前致谢,如有任何帮助,我将不胜感激。

如果格式始终为以下形式:

期刊={高分子化学与物理},

即journal 后接 3 个单词 然后使用以下内容:

查找:journal={(\w+)\s*(\w+)\s*(\w+)\s*(\w+)

替换为:journal={\u \u \l \u

如果您有更多单词要替换,您可以通过添加更多 \u\x 来修改它,其中 x 是单词的位置。

希望它能帮助您找到更好的解决方案。

\u 将下一个字母转换为大写(用于所有其他单词)

\l 将下一个字母转换为小写(用于单词“and”)

\1 替换第一个捕获的 () 搜索组

\2替换第2个捕获的()搜索组

\3替换第3个捕获的()搜索组

这适用于任意数量的单词:

  • Ctrl+H
  • 查找内容:(?:journal={|\G)\K(?:(\w{4,})|(\w+))(\h*)
  • 替换为:\u\E
  • 检查 环绕
  • 检查 正则表达式
  • 全部替换

解释:

(?:             # non capture group
    journal={     # literally
  |              # OR
    \G            # restart from last match position
)               # end group
\K              # forget all we have seen until this position
(?:             # non capture group
    (\w{4,})      # group 1, a word with 4 or more characters
  |              # OR
    (\w+)         # group 2, a word of any length
)               # end group
(\h*)           # group 3, 0 or more horizontal spaces

替换:

\u          # uppercased the first letter of the following
          # content of group 1
\E          # stop the uppercased
          # content of group 2
          # content of group 3

截图(之前):

截图(后):