It took me quite a while to guess that the replacement character for Search & Replace is not `$1` or `\1` but `\1`. [STFW](https://en.wikipedia.org/wiki/RTFM) came up empty, since most questions are about problems with the pattern, not with the replacement/substitution character.
I think this should be documented somewhere on https://www.geany.org/manual/gtk/glib/glib-regex-syntax.html or `<local_path>/doc/geany/html/index.html#regular-expressions`.
It is documented in [the manual](https://www.geany.org/manual/current/index.html#regular-expressions):
\n | Where n is 1 through 9 refers to the first through ninth tagged region when searching or replacing. Searching for (Wiki)\1 matches WikiWiki. If the search string was Fred([1-9])XXX and the replace string was Sam\1YYY, when applied to Fred2XXX this would generate Sam2YYY. -- | --
Maybe it needs to be called-out more, since the GLib docs don't do a good job either.
Maybe it needs to be called-out more, since the GLib docs don't do a good job either.
Yeah, glib documents it on the replace function https://developer.gnome.org/glib/stable/glib-Perl-compatible-regular-express... not in the regex syntax section so its not that obvious.
Thanks for pointing that out. I did not consider "replace" or "replacing" as a search keyword - I was looking for "replacement" and "substitution".
How about splitting the list up into characters used in the match, and characters used in the replacement, with separate headers?
May I also suggest replacing `\n` with `\1...\9`? Maybe that way it is easier to visually identify if you're looking for it, and less ambiguous (a literal `\n` means newline, and maybe someone reading the docs quickly just ignores that entry because they assume it's talking about the newline).
(And maybe it is a good idea to add a note in the documentation highlighting that `&` and `$1...$9` don't work as they do in other regex "dialects" such as Perl; it's `\0` and `\1...\9` here. After all, the documentation does claim that *"the syntax is Perl compatible"*, so one might assume this also applies to substitution patterns.)
It may be a little subtle, but the _regex_ syntax is Perl compatible, (and it is also yuckmascript compatible if a flag is set, Geany doesn't set it) but replacement isn't part of the regex syntax and thats why it isn't documented in the Glib regex syntax page.
My reference to Glib's replace is irrelevant, it appears that the replace is [Geany's own](https://github.com/geany/geany/blob/f1de94bb88f1c41c817a683da2d789561a36a9ce...) so its totally unrelated to any Perls, so yeah, it should be clearly documented in Geany docs.
Why the Geany docs [repeat](https://github.com/geany/geany/blob/master/doc/geany.txt#regular-expressions) the regex stuff I'm not sure, but I think its from back when it used a less common regex engine, but thats where the replace stuff is hidden, maybe it should be [here](https://github.com/geany/geany/blob/master/doc/geany.txt#replace).
Pull requests are welcome.
github-comments@lists.geany.org