(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

我不會用這個答案贏得任何正則高爾夫,但它有效。

使用中的指南德米特羅·朱巴克的回答(即在正規表示式模式下搜尋並選取“. matches newline”),進行以下更改:

尋找:^(S[^\r\n]+)(\r?\n?)\{(.*?)\}
取代:\1\2\{\2\}

訊息:
它現在確保括號前面的行以大寫 S 開頭

\1\2在替換表達式中引用查找表達式中的括號組。

相關內容