[{TableOfContents }]

Web browsers typically support some basic ''find'' functionality.
However, I needed in wiki Edit mode support for 
some more powerful find&replace functionality without going full wysiwyg.
\\The enclosed javascript does just that: it adds a Find&Replace toolbox
to the Edit screen supporting global replace functions,
__regular expressions__ (with help) and __Undo__ functionality.
\\--[DF|DirkFrederickx], Jun 2004
\\Updated Sep 2005 : toolbox is now fixed below the edit textarea, instead of a dropdown menu
--[DF|DirkFrederickx]

! Screenshot 

[BrushedScreenshotReplaceToolbar.jpg]

! Usage

* You can perform global find and replace operations on the edit textarea.
%%(background:yellow)
* (Jul 2006) find&replace is now also possible on a selection of your text; these are the steps to follow ...
** first enter all find and replace parameters (find:, replace:, and the different checkboxes)
** then, make your text selection
** finally press Replace, et voila, only the matches inside the selected text are replaced
%%
* The Undo button (only visible after a replace action) will recover the last text. Multiple undo-levels are supported (max 20)
* A Redo button is available to undo the undo.
* You can use regular expressions for complex find and replace needs. \\
  Mre info on [javascript regular expressions|http://www.regular-expressions.info/javascript.html]
  and [RegExp Sandbox|http://www.regular-expressions.info/javascriptexample.html].
  Also see [Regular Expression Syntax]\\  
  A ~RegExp help is available under the Help tab in Edit. See [EditFindAndReplaceHelp] page. 

%%( margin:2em; font-size:x-small; background:pink; )
You can use meta-characters in the ''Find'' field:

||.      |any character except newline    ||+      |one or more times
||*      |zero or more times              ||?      |zero or one time
||{n}    |match exact n times             ||{n,m}  |at least n, at most m times
||~|     |pipe: {{a~|b}} matches a or b   || -     |hyphen, match a range of chars
||^      |beginning of a line             ||$      |end of a line
||[[...] |one of the char's of a set      ||[[^...] |negated character set
||\b     |word boundary                   ||\B     |non word boundary
||\d     |numeral [[0-9]                  ||\D     |non numeral [[^0-9]
||\s     |single white space              ||\S     |single non white space 
||\w     |[[A-Za-z0-9_]                   ||\W     |[[^A-Za-z0-9_]
||(...)  |grouping are stored as $1..$9   ||\.     |escape a meta char

The ''Replace'' field can use $1..$9  as a backreference to parentheses of ''Find'' field.
----
Example:\\

Find __/abc|def/__ will match the word 'abc' or the word 'def'\\
Find __/bwiki/b__ will match the word 'wiki' but not the word 'jspwiki'\\
Find __^[[IVXMDCL]+\.__ will match any combination of roman numeral char's followed by a period\\
Find __/(-?\d+)(\d{3})/__ and replace with __$1,$2__ to insert commas in large integers. 

This is the [EditFindAndReplaceHelp] page.
[More info on regular expressions|http://www.regular-expressions.info/javascript.html]
and [RegExp Sandbox|http://www.regular-expressions.info/javascriptexample.html]\\
%%
 
----

Back to [BrushedTemplate]

! Comments & Discussion

--[DF|DirkFrederickx], 26 jun 2004\\
Added some regexp parameters to better support "^" and "$" metacharacters. 
Some other bug related to the undoMemory is also fixed.

--[DF|DirkFrederickx], Sep 2005\\
Major refactoring inline with latest update of [BrushedTemplate]

--[DF|DirkFrederickx], Jul 2006\\
Support Find&Replace on selection of text. Next to (multi-level)  UNDO also REDO is supported.