Clear every Item with Custom Lore or CustomModelData [duplicate]

Solution

Use data pack tags. Data packs allow you to define a tag which you can apply to different types of items, blocks, entities, fluids and functions. A tag is defined by a .json file containing a list of ids. You can use these tags to select multiple types of something at the same time.

Example of the solution

food.json:

{
    "values":[
        "minecraft:cake",
        "minecraft:apple",
        "minecraft:carrot",
        "minecraft:potato"
    ]
}

Every item listed in the file above can be selected using the food tag.

You want to clear all items with a specific NBT tag so you would need to create a tag that applies to every item in the game. This is how you would use that tag:

/clear @s #items_tag:all{NBT}

"#" means you are using a tag. "items_tag" is the namespace (folder) where the .json file is stored. And "all" is the name of the .json file (which is the name of the tag).

The clear command will go through the player's inventory and clear any items from the list defined in all.json if the NBT data matches.

How to implement the solution

These tag files are a part of the data pack system so you need to create a data pack before you can use it. Create a new folder and name it whatever you want. I'm going to name it "items tag". Then, create the following files are subfolders:

items tag
│   pack.mcmeta
│
└───data
    └───items_tag
        └───tags
            └───items
                    all.json

pack.mcmeta is a file that tells Minecraft that this is a data pack and it provides some information about the data pack.

items_tag is a namespace folder. Namespaces are used to organize files in data packs.

all.json is the file that defines the all tag.

Now all that's left to do is to populate the all.json file with item ids. You can copy the list from here and paste it into all.json. I extracted the list from a wiki page, so I'm not sure if it contains every single item. There are 973 ids in the list.

This is the bare minimum required to use tags in data packs. The wiki has a detailed explanation of the entire structure of data packs.