Re: Search/Replace capabilities of KATE 22.12.3

Rens Oliemans <[email protected]> Tue, 04 Feb 2025 11:34:38 +0100
Newsgroups gmane.comp.kde.general
Message-ID <[email protected]>
Hi Richard,

Richard Owlett <[email protected]> writes:

>    2. Is there documentation (preferably a tutorial) for this?

You already linked to the relevant documentation: The KatePart Handbook. The
relevant section is "Appendix A. Regular Expressions":

    https://docs.kde.org/stable5/en/kate/katepart/regular-expressions.html

Check especially the page on Patterns [0] and the "Capturing matching text =
(back
references)" paragraph: that paragraph is quoted in your stack overflow lin=
k.
It's rather concise for an examples/tutorial, but I'll an example below.

> I wish to write macros using ERE's[1] to make my project feasible.

This is not possible:

    [The Appendix] documents regular expressions in the form available with=
in
    KatePart, which is not compatible with the regular expressions of perl,=
 nor
    with those of for example grep.

    -- https://docs.kde.org/stable5/en/kate/katepart/regular-expressions.ht=
ml

However, I believe that the syntax exposed is very similar and powerful eno=
ugh.

>    1. Does that discussion apply to Kate 22.12.3?

Unfortunately I cannot check this definitively since I don't have that vers=
ion,
but the Kate Handbook is written for Version 22.08, so it should.

For an example of a regex replacement, I assume some basic knowledge about =
regex
expressions (documentation can be found in the KatePart or elsewhere for si=
milar
regex syntaxes). If things are unclear, feel free to ask.

Replacing the footnotes with uglier but easier clickable items. They were H=
TML
<sup>[n]</sup> items, but the superscript makes them difficult to click on =
small
screens. My goal:

Convert
  'Then the suitors came in and took their places on the benches and seats.=
<a href=3D"#linknote-3" id=3D"linknoteref-3" class=3D"pginternal"><sup>[3]<=
/sup></a> Forthwith men'
with
  'Then the suitors came in and took their places on the benches and seats.=
<a href=3D"#linknote-3" id=3D"linknoteref-3" class=3D"pginternal">[3]</a> F=
orthwith men'

Kate Replace:
  <sup>(\[\d+\])</sup> =E2=86=92 \1

Explanation: we find all <sup>...</sup> tags, and group the inner contents
with a sub expression. Our replacement text is simply \1, which a reference=
 to
the first sub expression.
=20=20

[0] https://docs.kde.org/stable5/en/kate/katepart/regex-patterns.html
[1] https://gutenberg.org/ebooks/1727

--=20
Best,
Rens