notepad ++查找某些行,将其更改(小写)

时间:2018-09-22 03:23:39

标签: regex notepad++

尝试通过正则表达式完成以下操作:

在以0开头的行中:我希望将单词从BLA_BLA更改为Bla Bla(删除下划线,并转换为小写字母,将每个单词的首字母大写)。

原文:

ACACIA_STAIRS:
  0: ACACIA_STAIRS
ACACIA_TRAPDOOR:
  0: ACACIA_TRAPDOOR
ACACIA_WOOD:
  0: ACACIA_WOOD
ACTIVATOR_RAIL:
  0: ACTIVATOR_RAIL
AIR:
  0: AIR
ALLIUM:
  0: ALLIUM
ANDESITE:
  0: ANDESITE

查找/替换帖子:

ACACIA_STAIRS:
  0: Acacia Stairs
ACACIA_TRAPDOOR:
  0: Acacia Trapdoor
ACACIA_WOOD:
  0: Acacia Wood
ACTIVATOR_RAIL:
  0: Activator Rail
AIR:
  0: Air
ALLIUM:
  0: Allium
ANDESITE:
  0: Andesite

任何帮助将不胜感激! 这是我要转换的完整文件:https://pastebin.com/raw/mKFcn9FM

1 个答案:

答案 0 :(得分:2)

Notepad ++(由于其支持boost语法)支持替换字符串中的条件语句,因此我们将这些字母转换为小写形式以及同时用空格字符替换下划线都没有问题。

(?>^\h*0:\W+\K|\G(?!^))(.)([a-zA-Z]+)(_+)?

并替换为

\U$1\L$2(?3 )

正则表达式细分:

(?> # Start of non-capturing group (atomic)
    ^\h*0:\W+\K # Match beginning of line following a sequence of spaces
                 # following `0:`  and some non-word characters
                 # then forget all (\K)
    | # Or
    \G(?!^) # Continue from previous match
) # End of non-capturing group
(.) # Capture first letter
([a-zA-Z]*) # Capture the rest of letters
(_+)? # Capture underscores, optionally