This is an old revision of the document!
Table of Contents
strreplace Plugin
Compatible with DokuWiki
adora belle, weatherwax
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
Similar to spreadout
This plugin will do a search and replace on up to four strings set in the Configuration Manager. It works transparently in the background. When the user opens the file in the editor, the new string is in place. When the file is saved the replacement becomes permanent.
Installation
Install the plugin using the Plugin Manager and the download URL above, which points to latest version of the plugin. Refer to Plugins on how to install plugins manually.
Usage
Enter up to four strings and their replacements in the Configuration Manager. Then set the 'do_replace' option to true. When the page is loaded into the editor the plugin will do the search and replace.
The Search and Replacement strings are numbered 1-4. The Search strings may be regular expressions as described below in the examples section.
The replacements are done in the editor when the page is loaded for editing. But the plugin understands Cancel
and the changes will not become permanent unless the page is saved.
The Search and Replace Session
The plugin keeps track of the pages which it has processed and will not re-process the same page twice during the same search and replace session. A session remains in effect for as long as the 'do_replace' option is set to true. To start a new session, set the 'do_replace' option to false, save the updated configuration, then reset it to true and re-save. Processing can also be suspended. See Configuration Options below.
Examples
Regular expressions must be bracketed by hashes:
#regex#
They can include PCRE internal options, though not all are guaranteed to work; you will have to test. All searches include the 'ms' options by default, but (?i) will set case insensitivity.
Example | Search | Replace |
---|---|---|
1 | Number | **Number** |
2 | #N.*?r# | **Number** |
3 | #(?i)N.*?r# | **Number** |
All will result in **Number**. But example 2 will also replace Newer
, while example 3 will replace both number
and never
by **Number**. Regular expressions should be used with care.
Also, it might be useful in some cases to know that the substitutions are done in order, that is,
Search Term 1
, Search Term 2
, etc.
Configuration Options
do_search | To do a search and replace, set this option to true. For each Search Term enter a Replacement at the same numbered position. strreplace keeps a list of the files it has processed. If this option is set to false after strreplace has been active, the list will be deleted. When it is re-set to true, a new session will be activated and all files will be re-processed. |
suspend | When set to true this option temporarily suspends the search and replace processing. This does not affect the list of previously processed files. The current session remains in effect. |
search_1 | Search Term 1: the search string entered here is replaced by Replacement 1, etc. Search terms and their replacements can be set at any time, even during an active session. However, only pages which have not already been processed will be affected by the new setting. |
search_2 | Search Term 2 |
search_3 | Search Term 3 |
search_4 | Search Term 4 |
replace_1 | Replacement 1 |
replace_2 | Replacement 2 |
replace_3 | Replacement 3 |
replace_4 | Replacement 4 |
Discussion
Replace word into same word but on a new line
Is it possible to search on the word '<code' that is not starting at the beginning of a new line and replace it by '<code' but on a new line?
For example:
this is a test<code php>
should be replaced into
this is a test
<code php>