Notepad++:使用替换提取文本,以大写字母/混合大小写开头的单词

Notepad++:使用替换提取文本,以大写字母/混合大小写开头的单词

我想要做的是:

  1. 提取任意两个或多个以大写字母开头的连续单词。
  2. 提取大小写混合的单个单词。(编辑:大小写混合,包含多个大写字母,基本上是大写字母开头的连续单词的帕斯卡大小写)
  3. 将每个项添加为新行

例子:

This is a Text That contains CapitalLetters.

输出:

Text That
CapitalLetters

答案1

这可以分两步完成:

  • 第一步:只保留想要的单词

  • Ctrl+H
  • 找什么:\b(?:[A-Z]\w*(?:\h+[A-Z]\w*)+|[A-Z]\w*[A-Z]\w*)\b(*SKIP)(*FAIL)|[\w.]+\h*
  • 替换为:\n\r\n取决于平台
  • 查看 相符
  • 查看 环绕
  • 查看 正则表达式
  • Replace all

解释:

\b              # word boundary
(?:             # start non capture group
    [A-Z]           # a capital letter at beginning of word
    \w*             # 0 or more word character
    (?:             # start non capture group
        \h+             # 1 or more horizontal spaces
        [A-Z]           # a capital letter at beginning of word
        \w*             # 0 or more word character
    )+              # end group, must appear 1 or more times
  |               # OR
    [A-Z]           # a capital letter at beginning of word
    \w*             # 0 or more word character
    [A-Z]           # a capital letter somewhere in the word
    \w*             # 0 or more word character
)               # end group
\b              # word boundary
(*SKIP)         # Skip what was matched
(*FAIL)         #   Assert the match failed
  |               # OR
[\w.]+          # 1 or more word character or dot
\h*             # 0 or more horizontal spaces

截图(之前):

在此处输入图片描述

截图(之后):

在此处输入图片描述


  • 第二步:删除空行
Menu Edit >> Line Operations >> Remove Empty Lines

相关内容