The algorithm for "replace all" in WikiEditor, as described in a comment in modules/jquery.wikiEditor.dialogs.config.js, is the following: "Instead of using repetitive .match() calls, we use one .match() call with /g and indexOf() followed by substr() to find the offsets."
In general, this does not work when regular expression mode is turned on and the regular expression contains "^" or "$", because calling indexOf on the matched text ignores the constraint that this text must be at the beginning/end of a line.
- Open a page in edit mode and set the text of the edit box to "aa"
- Open the search and replace dialog of WikiEditor.
- Set "search for" to "a$"
- Set "replace with" to "b"
- Enable "Treat search string as a regular expression"
- Click "Replace all"
Expected result: "ab"
Real result: "ba"
What happens: the content of the only match is "a", and the first occurrence of "a" in "aa" is at position 0.