You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用正则表达式仅大写参考文献Title字段内的单词?

Solution to Capitalize Title Words in Reference Files

Let's fix your regex issue and get those title words properly capitalized!

Why Your Original Regex Didn't Work

Your regex (?<=Title)(\b.+?\b) only targets the first word after "Title" because:

  • The non-greedy .+? stops at the first word boundary (\b) right after "Title"
  • It doesn't restrict matches to the content inside the {} brackets, so it could accidentally pick up unrelated text elsewhere in your file

Correct Approach: Target Title Content & Capitalize Each Word

We need to first isolate the text inside Title = { ... }, then capitalize the first letter of every word (including those after hyphens, like bi-elemental → Bi-Elemental).

1. For VS Code (Most Flexible)

Enable regex mode (click the .* button in the search/replace panel):

  • Find: (?<=Title = {)(.*?)(?=})
  • Replace: ${1/(^|\s|-)([a-z])/$1\u$2/g}

This works by:

  • Capturing all text inside the title brackets
  • Running a nested regex on that captured text to find:
    • The start of the string, a space, or a hyphen (^|\s|-)
    • Followed by a lowercase letter ([a-z])
  • Replacing with the preceding character plus the uppercase version of the letter ($1\u$2), applied globally (g)

2. For Sublime Text

Enable regex mode:

  • Find: (Title = {)(.*?)(})
  • Replace: $1${2/(\b|-)([a-z])/$1\u$2/g}$3

3. For Notepad++

Enable Perl-compatible regex (check the box in the replace dialog):

  • Find: (?<=Title = {)(\b[a-z]|[-][a-z])
  • Replace: \u$0

This directly matches every lowercase letter that starts a word (or comes after a hyphen) inside the title brackets, then uppercases it.

Example Result

Original line:

... Title = {Direct synthesis of antimicrobial coatings based on tailored bi-elemental nanoparticles}, journal={APL Mat.}, ...

After replacement:

... Title = {Direct Synthesis of Antimicrobial Coatings Based on Tailored Bi-Elemental Nanoparticles}, journal={APL Mat.}, ...

内容的提问来源于stack exchange,提问作者Giulio Benetti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:48:40