Anonymize content in a Confluence page with regex using Confluence CLI

This article explains how to anonymize content in a Confluence page with regex using the app, Confluence Command Line Interface.


Use the modifyPage action with the space and title parameters to modify the page. Here are the details:

  1. Ensure that you update the file with the server, user, and password details.
    • Option 1: 
      To change each and every content on the confluence page to a specific value then use the following action (Ex: Below action changes all the content to X)

      --action modifyPage --space "CLI" --title "Table" --findReplaceRegex "[(?<*>)(a-zA-Z0-9)]:X"

      The regex conversion takes place based on the storage format of the Confluence page. The data displayed on the page cannot be preserved using the regex. 
      Replace the space name with the intended name of the space in the above syntax. (Here in the example the space name and the space key is the same i.e, CLI)

    • Option 2:
      To change a specific content on the confluence page then use the below action:

      --action modifyPage --space "CLI" --title "Table" --findReplaceRegex "BobSwift:Anonymous"
    The result of the given action is as follows:

    • Output on the terminal:

      --action modifyPage --space "CLI" --title "Table" --findReplaceRegex "[(?<*>)(a-zA-Z0-9)]:X"
      Page 'Table' in space CLI modified. Page has id 1114250.

    • Output in Confluence:

      Please refer to How to use regular expression for further details. 

  • It is highly recommended that you test the actions on a test instance before executing it in the production environment. 
  • As a precautionary measure, take a backup of the instance before executing the command.