Help required to remove unwanted strings of text
- 
 I need to be able to delete all text between { } that do not contain ‘XboxOfficial’, would like to delete the bottom text, but keep the top. This is for over 10000 lines of code. 
- 
 Hello, @muslim-farmer, This could be probably achieved with regular expressions ! But I need additional information : Let’s imagine a {........}block which does not contain the wordXboxOfficial, as below :},{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XBlaBlahOfficial-Ragnarok495", "Port": 9990, },{Two questions : - 
Firstly, is the word XboxOfficialalways located after the “Name”: statement ?
- 
Secondly, do you expect the replaced text to be : 
 A) All that bloc is deleted : },{B) Only the lines, after the line containing a name different from XboxOfficial, till the ending boundary}, are deleted :},{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XBlablahOfficial-Ragnarok495", },{C) Only the lines, including the line containing a name different from XboxOfficial, till the ending boundary}, are deleted :},{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", },{Best Regards, guy038 
- 
- 
 @guy038 I desire the whole block to be deleted if it is not present. 
- 
 Hello, @muslim-farmer and All, EDIT : Have also a look to my next post for a more correct syntax of the search regex ! OK ! So, assuming the sample text, below : },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 9990, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XBlablaOfficial-Ragnarok495", "Port": 9990, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XBlablaOfficial-Ragnarok495", "Port": 9990, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 9990, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-An OTHER value-Ragnarok495", "Port": 9990, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 9990, },{- 
Open the Replace dialog ( Ctrl + H)
- 
SEARCH (?s)\{((?!XboxOfficial).)+?\}
- 
REPLACE Leave EMPTY
- 
Tick, preferably, the Wrap aroundoption
- 
Select the regular expressionsearch mode
- 
Click, once on the Replace Allbutton or several times on theReplacebutton
 You should get the expected text : },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 9990, },,,{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 9990, },,{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 9990, },{All the blocks which contain, in the Namepart, an other string thanXboxOfficialare totally deleted ;-))If my first attempt is the good one, I’ll explain to you how the regex works, next time ! Best Regards, guy038 
- 
- 
 I think this RegEx will do the trick: \{(?!([^\{\}]*(\b)(XboxOfficial|Xbox360)(\b)[^\{\}]*)).*?\}\,It uses a “keyword”-list for whether or not a block of code will be removed. In the RegEx this is the part: (XboxOfficial|Xbox360) 
 Between the parenthesis you can add/remove keywords, as long as they are separated by a | character (pipeline).- Open the Find/Replace
- Select the tab: Mark
- Copy the RegEx into Find what:
- Look at the images for the other settings to make this work!
- Click on Mark All and NPP will highlight the text matched by the RegEx.
- Especially when you are using the RegEx for the first time, verify that all the highlighted text is indeed the part you want to remove!
- If so: Click on the Tab: Replace
- Find what must still contain the RegEx.
- Leave Replace with: EMPTY
- You can click on the Replace button a few times to check if the highlighted text is being removed. When this works then you can click on Replace All.
- When NPP is done removing the rest, there should be no highlighted text anymore.
 3 blocks marked 
 3 blocks deleted4 blocks marked 
 4 blocks deletedThe samples as text code: The sample text that I've used },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 0001, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-PlaystationOfficial-Ragnarok495", "Port": 0002, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxUNOfficial-Ragnarok495", "Port": 0003, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok", "Port": 0004, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 0005, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-Xbox360-Ragnarok495", "Port": 0006, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Frank123", "Port": 0007, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 0008, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-C64Official-Ragnarok495", "Port": 0009, },{. With 1 Keyword matching (XboxOfficial|ZXSpectrum) },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 0001, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok", "Port": 0004, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 0005, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Frank123", "Port": 0007, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 0008, },{. With 2 Keywords matching (XboxOfficial|Xbox360) },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 0001, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok", "Port": 0004, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 0005, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-Xbox360-Ragnarok495", "Port": 0006, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Frank123", "Port": 0007, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 0008, },{Important! 
 Each block of text between the { and }, that contains a word from the RegEx word-list will NOT be selected for removal.(This is my first post on the NPP Community so forgive me for when I’ve done something “not correctly” according to the rules.) 
- 
 Hello, @muslim-farmer, @fotofrank and All, @fotofrank, welcome to the Notepad++ Community ! Studying your version of the search regex and looking at the results after replacement, of my previous post, I just realized that I omitted to get rid of the comma, in the string },{Of course, the correct version of my regex is : (?s)\{((?!XboxOfficial).)+?\},Leading to these results : },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 9990, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 9990, },{ "ClusterId": "NewXboxPVP", "IP": "37.10.124.94", "Name": "NA-PVP-XboxOfficial-Ragnarok495", "Port": 9990, },{Cheers, guy038 P.S. : @fotofrank, in order that your regex works correctly, you must, either : - 
Tick the . matches newlineoption of the Replace dialog
- 
Add, at a location before the dot meta-character, the in-line modifier (?s)which means that any further dot (.) will match, absolutely, any single character ( EOL or standard ones )
 So, one of the two regexes, below : SEARCH (?s)\{(?!([^\{\}]*\b(XboxOfficial|Xbox360)\b[^\{\}]*)).*?\},SEARCH \{(?!([^\{\}]*\b(XboxOfficial|Xbox360)\b[^\{\}]*))(?s).*?\},
- 
- 
 Thanks! 
 Though I’m using Regular Expressions a LOT, I’m always forgetting about the in-line modifiers.Greetz, 
 fotofrank

