# Clearing all CellTags in a notebook

Below is some code that will delete all CellTags in a notebook where the CellTag is given by the string "temp".

NotebookLocate[{InputNotebook[], "temp"}];
SelectionMove[InputNotebook[], All, Cell];
SetOptions[NotebookSelection[], CellTags -> {}];


However, I want delete every CellTag in the notebook so there are none left at all. I tried replacing "temp" with * but that doesn't work. Any ideas here?

Here is an alternative:

Scan[SetOptions[#, CellTags -> {}] &, Cells[InputNotebook[]]]

• This does evaluate faster. – Michael McCain Oct 9 '16 at 9:56

Try

NotebookPut[NotebookGet@#/.(CellTags->_)->Sequence[],#]&@InputNotebook[];


This removes all the celltags in the current notebook.

• Updated to overwrite the current notebook in one step – dan7geo Oct 9 '16 at 9:29
• I was about to say... I needed a solution for the current notebook. But looks like you got it solved. Thanks again! – Michael McCain Oct 9 '16 at 9:30
• No problem! I must say it's really pleasing to see how Mathematica lets you seamlessly integrate pattern matching, pure functions, and the fact that everything is an expression. – dan7geo Oct 9 '16 at 9:34
• @Kuba It did disappear from the notebook expression without any error messages in version 11.0 on Windows. I'm actually surprised that it works :D – dan7geo Oct 9 '16 at 9:42
• Updated to fix the error message – dan7geo Oct 9 '16 at 9:44