我正在使用文本编辑器将参考文件中的论文标题大写。
我有类似的结构
...
Title = {Direct synthesis of antimicrobial coatings based on tailored bi-elemental nanoparticles},
journal={APL Mat.},
...
我想只将标题部分中的单词大写,以便它变为
...
Title = {Direct Synthesis of Antimicrobial Coatings Based on Tailored Bi-Elemental Nanoparticles},
journal={APL Mat.},
...
我尝试使用lookbehing正则表达式以下列方式搜索每个字后跟单词“Title”
(?<=Title)(\b.+?\b)
我想用
替换它\u\1
对于文本中的每个事件。 但是我的代码只选择标题的“e”后面的字符和 Direct 的“D”,而后面的找不到其他字符这一点。
你能帮帮我吗?谢谢。答案 0 :(得分:2)
您可以使用
(\G(?!^)(?:[^}\n\w]+(?:o[fn]|in|the|by|for|to|and*|a))*[^}\n\w]+|Title\s*=\s*\{)(\w+)
并替换为$1\u$2
。请参阅regex demo(由于regex101似乎不支持\u
运算符,因此略有修改。)
<强>详情
(\G(?!^)(?:[^}\n\w]+(?:o[fn]|in))*[^}\n\w]+|Title\s*=\s*\{)
- 两种选择中的任何一种:
\G(?!^)(?:[^}\n\w]+(?:o[fn]|in|the|by|for|to|and*|a))*[^}\n\w]+
:\G(?!^)
- 上一场比赛结束(?:[^}\n\w]+(?:o[fn]|in))*
- 重复0次或更多次
[^}\n\w]+
- 除}
以外的1个或多个字符,LF和单词char (?:o[fn]|in|the|by|for|to|and*|a)
- of
,on
或in
等(添加更多应从大写字母排除的字词)[^}\n\w]+
- 除}
以外的1个或多个字符,LF和单词char |
- 或Title\s*=\s*\{
- Title
,=
附有0 +空格和{
(\w+)
- 第2组:一个或多个单词字符。