Tags:
create new tag
view all tags

Replace Text Plugin

Globally search and replace text in all topics of a web

Replace Text Form

ALERT! ATTENTION: Use with caution, it is possible to change many topics at once!

Replace Text
Web:
From:
To:
Test:
 
Result: %REPLACETEXT{ action="" web="" from="" to="" search="\b$from\b" replace="$to" dryrun="" }%

Syntax Rules

%REPLACETEXT{ action="..." web="..." from="..." to="..." }%

Parameter Description Default
action="..." Replace action:
"" - no action
"replace" - do replace action based on below parameters, return result message, such as:
  Replaced FOO with BAR in 2 topics in Sandbox web
""
web="..." Name of web to search and replace text (current web)
topic="..." Expert mode: Limit topics by name: A topic with asterisk wildcards, such as Bug-*, or a list of topics separated by comma (all topics)
filter="..." Expert mode: Limit topics by filtering topic text with a regex filter, optional (no filter)
from="..." Text to search (none, required)
to="..." Replacement text (none, required)
search="..." Expert mode: Use this for more complex replace using regular expression grouping etc; typically supplied via a hidden input field. Use $from to specify the search text entered by the user "\b$from\b"
replace="..." Expert mode: Use this for more complex replace using regular expression grouping etc; typically supplied via a hidden input field. Use $to to specify the replacement text entered by the user, use $1, $2, etc to reference captured groups "$to"
dryrun="1" Do a dry run, e.g. a search only to simulate the replace action "0"
showlist="1" Show the list of topics replaced "0"

See details at REPLACETEXT.

Security and Known Issues

  • This plugin ignores locked topics, it writes over locked topics.
  • This plugin is potentially dangerous. Security measures:
    1. The operations of this plugin is restricted to members of the TWikiAdminGroup. This can be changed with the $TWiki::cfg{Plugins}{ReplaceTextPlugin}{AccessGroup} configure setting.
    2. For public sites, it is recommended to enable this plugin only for the short time when needed (it is enabled if the following variable shows "installed": %REPLACETEXT{action="check"}%).
  • This plugin has been tested. However, operator errors can be done quite easily, especially if regular expressions are not well understood. This plugin does not have ANY WARRANTY, does not even have the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Custom Replacement For Developers

You can ignore this section unless you want to add custom search and replace code.

By default, the plugin uses from, to, search, replace parameters, as documented at REPLACETEXT. The search and replace parameters allows for more complex search and replace operations using regular expression grouping.

If you need even more control over search and replace you can write your own search and replace module, such as to sort a list based on the search and replace operation. For this you can clone and modify twiki/lib/TWiki/Plugins/ReplaceTextPlugin/CustomReplace.pm. Specify the name of your module in the $TWiki::cfg{Plugins}{ReplaceTextPlugin}{CustomReplace} configure setting, such as 'TWiki::Plugins::ReplaceTextPlugin::MyReplace'.

Add a function as follows:

replaceText( $web, $topic, $text, $search, $replace ) -> $text

  • =$web: =Name of web
  • =$topic: =Name of topic
  • =$text: =Text of topic
  • =$search: =Text to search for
  • =$replace: =Text to replace with
  • =return: =Text with replacement

Plugin Installation & Configuration

You do not need to install anything on the browser to use this plugin. These instructions are for the administrator who installs the plugin on the TWiki server.

  • For an automated installation, run the configure script and follow "Find More Extensions" in the in the Extensions section.

  • Or, follow these manual installation steps:
    • Download the ZIP file from the Plugins home (see below).
    • Unzip ReplaceTextPlugin.zip in your twiki installation directory. Content:
      File: Description:
      data/TWiki/ReplaceTextPlugin.txt Plugin topic
      data/TWiki/VarREPLACETEXT.txt Variable documentation
      lib/TWiki/Plugins/ReplaceTextPlugin.pm Plugin Perl module
      lib/TWiki/Plugins/ReplaceTextPlugin/Config.spec Configuration spec file
      lib/TWiki/Plugins/ReplaceTextPlugin/Core.pm Plugin core module
      lib/TWiki/Plugins/ReplaceTextPlugin/CustomReplace.pm Template for custom replace module
    • Set the ownership of the extracted directories and files to the webserver user.

  • Plugin configuration:
    • Run the configure script and enable the plugin in the Plugins section.

  • Test if the configuration is successful:
    • Try the replacement form above, preferably with the Sandbox web

Plugin Info

  • Set SHORTDESCRIPTION = Globally search and replace text in all topics of a web

Author: TWiki:Main.PeterThoeny, TWiki.org
Copyright: © 2019-2023 ALPS Plastic.
© 2019-2023 TWiki:Main.PeterThoeny
© 2019-2023 TWiki:TWiki.TWikiContributor
License: GPL (GNU General Public License)
Sponsor: ALPS Plastic
Version: 2023-06-26
2023-06-30: TWikibug:Item7864: Add topic="", filter="", and showlist="" parameters
2021-04-21: TWikibug:Item7864: Escape special characters such as parenthesis in from parameter
2019-05-05: TWikibug:Item7864: Support special case when using $1, $2, etc in replace
2019-05-04: TWikibug:Item7864: Initial version of ReplaceTextPlugin
TWiki Dependency: $TWiki::Plugins::VERSION 1.2
CPAN Dependencies: none
Other Dependencies: none
Perl Version: 5.008
Plugin Benchmark: GoodStyle nn%, FormattedSearch nn%, ReplaceTextPlugin nn%
Home: http://TWiki.org/cgi-bin/view/Plugins/ReplaceTextPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/ReplaceTextPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/ReplaceTextPluginAppraisal

Related: VarREPLACETEXT

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatmd5 ReplaceTextPlugin.md5 r9 r8 r7 r6 r5 manage 0.2 K 2023-06-30 - 07:44 PeterThoeny  
Compressed Zip archivetgz ReplaceTextPlugin.tgz r9 r8 r7 r6 r5 manage 8.5 K 2023-06-30 - 07:44 PeterThoeny  
Compressed Zip archivezip ReplaceTextPlugin.zip r9 r8 r7 r6 r5 manage 13.1 K 2023-06-30 - 07:44 PeterThoeny  
Unknown file formatext ReplaceTextPlugin_installer r1 manage 3.6 K 2023-06-30 - 07:44 PeterThoeny  
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2023-06-30 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.