Search/Replace capabilities of KATE 22.12.3

Rens Oliemans hallo at rensoliemans.nl
Tue Feb 4 10:34:48 GMT 2025


Hi Richard,

Richard Owlett <rowlett at access.net> 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 link.
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 within
    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.html

However, I believe that the syntax exposed is very similar and powerful enough.

>    1. Does that discussion apply to Kate 22.12.3?

Unfortunately I cannot check this definitively since I don't have that version,
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 similar
regex syntaxes). If things are unclear, feel free to ask.

Replacing the footnotes with uglier but easier clickable items. They were HTML
<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="#linknote-3" id="linknoteref-3" class="pginternal"><sup>[3]</sup></a> Forthwith men'
with
  'Then the suitors came in and took their places on the benches and seats.<a href="#linknote-3" id="linknoteref-3" class="pginternal">[3]</a> Forthwith men'

Kate Replace:
  <sup>(\[\d+\])</sup> → \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.
  

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

-- 
Best,
Rens


More information about the kde mailing list