简体   繁体   中英

Notepad++ How to replace everything in between certain lines

So I have a code like this

TitleManager:AddSubTitleMissionInfo_LUA({
  m_iID = 10,
  m_wstrDescription = "Professional Killer",
  m_eClearType = TITLE_MISSION_CLEAR_TYPE.TMCT_MOB_KILL_COUNT,
  m_bAutomaticDescription = True,
  m_ClearCondition = {
    m_eMobID = {68},
    m_iMobKillCount = {1}
  }
})
TitleManager:AddSubTitleMissionInfo_LUA({
  m_iID = 20,
  m_wstrDescription = "Sneaky Assassin",
  m_eClearType = TITLE_MISSION_CLEAR_TYPE.TMCT_MOB_KILL_COUNT,
  m_bAutomaticDescription = True,
  m_ClearCondition = {
    m_eMobID = {69},
    m_iMobKillCount = {1}
  }
})
TitleManager:AddSubTitleMissionInfo_LUA({
  m_iID = 20,
  m_wstrDescription = "Merciless Thug",
  m_eClearType = TITLE_MISSION_CLEAR_TYPE.TMCT_MOB_KILL_COUNT,
  m_bAutomaticDescription = True,
  m_ClearCondition = {
    m_eMobID = {70,71},
    m_iMobKillCount = {1,1}
  }
})

There are like a hundred of those, all different. How do I replace everything in between the curly brackets.

m_ClearCondition = {

}

to

m_ClearCondition = {
m_eMobID = {50},
m_iMobKillCount = {1}
}

I really hope someone could answer my question, I would be really grateful.

Description

There are several unclear things about your sample text from your post. But this expression assumes:

  • each m_clearcondition value will have no nested brackets more then one level deep.
  • will find each key name m_clearcondition and place that into capture group 1
  • the close bracket will be captured into group 2

Regex:

^(\s+m_ClearCondition\s*=\s*\{)(?:\{[^}]*\}|[^}])*(\})

Replace with:

$1\n    m_eMobID = {50},\n    m_iMobKillCount = {1}\n  $2

Example:

Live demo of the regex: http://regexr.com?35n0l

在此处输入图片说明

In this example I'm using Notepad++ 6.4.2. There where known problems using regex in Notepad version 5 and lower.

Regex is your friend. Ctrl-H (Find/replace) and enable regular expressions (bottom left of dialog).

\{\s*\}$

replace with:

{\nwhatever you want\n}\n

Regex Match Explanation:

  • {} are reserved, so escaping them will match the actual brace character
  • \\s of course will match all whitespace (including new lines and tabs)
  • $ would be the end of the line; this just helps the match
  • \\n in the replace would insert new lines where it makes sense; these are optional.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM