1

我在一个文件中有数百个 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++ 中对期刊名称进行标题大小写(又名正确大小写)。例如,从Macromolecular chemistry and physicsMacromolecular Chemistry and Physics

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

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

但我无法通过 Edit > Convert Case to 更改大小写。显然它不适用于查找所有内容,我必须一一进行。

接下来,我尝试录制并运行一个宏,但是当我尝试运行它时,Notepad++ 只是无限期挂起(运行到文件末尾的选项)。

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

提前谢谢你,我会很感激任何帮助。

4

2 回答 2

2

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

  • Ctrl+H
  • 找什么:(?:journal={|\G)\K(?:(\w{4,})|(\w+))(\h*)
  • 用。。。来代替:\u$1\E$2$3
  • 检查 环绕
  • CHECK 正则表达式
  • Replace all

解释:

(?:             # 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
  $1        # content of group 1
\E          # stop the uppercased
$2          # content of group 2
$3          # content of group 3

截图(之前):

在此处输入图像描述

截图(之后):

在此处输入图像描述

于 2020-07-18T08:48:59.823 回答
1

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

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

即日志后跟3个单词,然后使用以下内容:

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

用。。。来代替:journal={\u\1 \u\2 \l\3 \u\4

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

希望它有助于给您一个想法,以寻求更好的解决方案。

在此处输入图像描述

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

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

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

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

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

于 2020-07-18T01:47:00.447 回答