(Notepad++)删除括号之间的文本,但不是所有括号内的文本

(Notepad++)删除括号之间的文本,但不是所有括号内的文本

所以我发了之前的一个问题并得到了用户 Dmytro Dzyubak 的回答,一切正常,但现在我想让它运行得更快。更多详细信息如下。

前:

SkinMesh
{
    skin = "Art/Models/Effects/enviro_effects/misc/blood_orb/BloodOrb.sm"
}

SoundEvents
{
    soundbank = "_Effects_misc_blood_orbs.bank"
    animation = "enter"
        0 = "Audio/Sound Effects/Misc/BloodOrb/Start_$(#).ogg@2 120 0 0.1 0.1 0 -1 0 1 1"
    animation = "exit"
        0 = "Audio/Sound Effects/Misc/BloodOrb/End_$(#)[email protected] 115 0 0 0 0 -1 0 1 1"
    animation = "idle"
        0 = "Audio/Sound Effects/Misc/BloodOrb/Orb_$(#)[email protected] 115 0 0 0 0 -1 0 10 4.5"
}

BoneGroups
{
    bone_group = "mid false mid jnt_orb_01 "
    bone_group = "cyl false mid cyl "
    bone_group = "explode false jnt_orb_01 up_explode "
    bone_group = "explodecyl false jnt_orb_01 cyl_explode1 "
    bone_group = "midparticle false mini_orb1 mini_orb_particleup_02 "
}

如您所见,有一堆括号。是否可以只删除里面的文本:

SkinMesh
{
    skin = "Art/Models/Effects/enviro_effects/misc/blood_orb/BloodOrb.sm"
}

SoundEvents
{
    soundbank = "_Effects_misc_blood_orbs.bank"
    animation = "enter"
        0 = "Audio/Sound Effects/Misc/BloodOrb/Start_$(#).ogg@2 120 0 0.1 0.1 0 -1 0 1 1"
    animation = "exit"
        0 = "Audio/Sound Effects/Misc/BloodOrb/End_$(#)[email protected] 115 0 0 0 0 -1 0 1 1"
    animation = "idle"
        0 = "Audio/Sound Effects/Misc/BloodOrb/Orb_$(#)[email protected] 115 0 0 0 0 -1 0 10 4.5"
}

并且不改变 BoneGroups 吗?

以下是其外观的示例:

SkinMesh
{
}

SoundEvents
{
}

BoneGroups
{
    bone_group = "mid false mid jnt_orb_01 "
    bone_group = "cyl false mid cyl "
    bone_group = "explode false jnt_orb_01 up_explode "
    bone_group = "explodecyl false jnt_orb_01 cyl_explode1 "
    bone_group = "midparticle false mini_orb1 mini_orb_particleup_02 "
}

答案1

  • Ctrl+H
  • 找什么:\b(?:SkinMesh|SoundEvents)\s+\{\K.+?(?=\})
  • 用。。。来代替:\n
  • 检查匹配大小写
  • 检查环绕
  • 检查正则表达式
  • 查看. matches newline
  • Replace all

解释:

\b                  # word boundary
(?:                 # start non capture group
    SkinMesh        # literally "SkinMesh"
  |                 # OR
    SoundEvents     # literally "SoundEvents"
)                   # end group
\s+                 # 1 or more any spaces (including linebreak)
\{                  # openning curly bracket
\K                  # forget all we have seen until this position
.+?                 # 1 or more any characters including linebreak
(?=\})              # positive lookahead, make sure we have a closing curly bracket after.

替代品:

\n      # linefeed, you may use \r\n

给定示例的结果:

SkinMesh
{
}

SoundEvents
{
}

BoneGroups
{
    bone_group = "mid false mid jnt_orb_01 "
    bone_group = "cyl false mid cyl "
    bone_group = "explode false jnt_orb_01 up_explode "
    bone_group = "explodecyl false jnt_orb_01 cyl_explode1 "
    bone_group = "midparticle false mini_orb1 mini_orb_particleup_02 "
}

屏幕截图:

在此处输入图片描述

答案2

我不会凭借这个答案赢得任何 RegEx Golf,但它确实有效。

使用指南Dmytro Dzyubak 的回答(即在 RegEx 模式下搜索并选中“。匹配换行符”),进行以下更改:

查找:^(S[^\r\n]+)(\r?\n?)\{(.*?)\}
替换:\1\2\{\2\}

信息:
它现在确保括号前面的行以大写 S 开头。
它还会捕获行尾并替换它(这样您就不会得到混合的行尾)。
\1\2在替换表达式中引用查找表达式中的括号组。

相关内容