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

正则表达式需求:匹配非单大写字母后句号及批量移除方法咨询

Solution to Your Regex & Batch Removal Questions

1. Regex to Match Periods (Excluding Those After Isolated Uppercase Letters)

First, let's break down your requirement: we need to match all periods except when they follow a single, isolated uppercase letter (like J. or the periods in F.C.). Periods after full words (whether lowercase, title case, or all caps, e.g., word., Word., WORD.) should be matched.

Here's the regex that does exactly this:

(?<!\b[A-Z]\b)\.

How it works:

  • \. matches a literal period (we escape it because . is a special character in regex).
  • (?<!...) is a negative lookbehind assertion—it ensures the period is not preceded by the pattern inside.
  • \b[A-Z]\b matches an isolated uppercase letter:
    • \b is a word boundary, meaning the uppercase letter ([A-Z]) is surrounded by non-word characters (like spaces, periods, or the start/end of text) on both sides.

Let's test it against your examples:

  • ❌ J. → The period follows an isolated J, so it's excluded.
  • ❌ F.C. → Both periods follow isolated F and C, so they're excluded.
  • ✅ word. → Period follows a lowercase word, so it's matched.
  • ✅ Word. → Period follows a title-case word, so it's matched.
  • ✅ WORD. → Period follows an all-caps word (not an isolated letter), so it's matched.

2. Batch Remove Matched Periods in Text Editors

Most modern text editors support regex-based find-and-replace. Here's how to do it in three popular tools:

VS Code

  1. Open your large text file in VS Code.
  2. Press Ctrl+H (Windows/Linux) or Cmd+H (Mac) to open the Replace panel.
  3. Click the .* button (regex mode) in the top-right corner of the panel to enable regex matching.
  4. Paste the regex (?<!\b[A-Z]\b)\. into the "Find" field.
  5. Leave the "Replace" field empty (since we want to remove the matched periods).
  6. Click "Replace All" (the icon with two arrows) to process the entire file.

Sublime Text

  1. Open your file in Sublime Text.
  2. Press Ctrl+H (Windows/Linux) or Cmd+H (Mac) to open the Replace panel.
  3. Click the regex icon (looks like .*) in the top-left of the panel to switch to regex mode.
  4. Enter (?<!\b[A-Z]\b)\. in the "Find What" field.
  5. Leave "Replace With" blank.
  6. Click "Replace All" to remove all matched periods.

Notepad++

  1. Open your file in Notepad++.
  2. Press Ctrl+H to open the Replace dialog.
  3. Switch to the "Replace" tab.
  4. Under "Search Mode", select "Regular expression".
  5. In the "Find what" box, enter (?<!\b[A-Z]\b)\..
  6. Leave "Replace with" empty.
  7. Click "Replace All" to apply the changes.

⚠️ Important Note: Always make a backup of your large text file before performing batch edits—this prevents data loss if something unexpected happens.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:11:22