Bug 501413 - Find / Replace not working with regular expression
Summary: Find / Replace not working with regular expression
Status: CONFIRMED
Alias: None
Product: kate
Classification: Applications
Component: search (show other bugs)
Version: 24.12.3
Platform: Other Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-12 16:11 UTC by Jacob
Modified: 2025-03-13 06:56 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jacob 2025-03-12 16:11:17 UTC
SUMMARY
When entering certain regular expressions in Search / Replace, the Replace function does not work.


STEPS TO REPRODUCE
1. Enter the following into a new text file:
Phrase A: Words
Phrase A: Words
Phrase A: Words
Phrase B: Words
Phrase B: Words
Phrase A: Words
Phrase A: Words
Phrase B: Words
Phrase A: Words
Phrase A: Words

2. Open Search window on bottom

3. Enable Regular Expressions and Expand Results

4. Enter the following in Search: `(?<=Phrase A: ).*[\r\n]+\KPhrase A: `

5. This PCRE Regular Expression finds and selects a specified phrase at the beginning of sentences, **only if** it is preceded by a sentence that also contains the phrase. The first sentence containing the phrase is **not** selected. So in this example, it finds `Phrase A: ` in lines 2, 3, 7, and 10.

6. Enter any text for replacement, or leave blank for deletion. Click the "Replace" button.

OBSERVED RESULT
It cycles through the results but has no effect. Nothing is replaced.


EXPECTED RESULT
Highlighted found results should be replaced by whatever is entered in "Replace" field.


SOFTWARE/OS VERSIONS
Windows: 10 Professional 2004


ADDITIONAL INFORMATION
From what I checked so far, this behavior exists as far back as 2022 (v22.08.1) and is still present in the latest nightly builds.
Comment 1 Jacob 2025-03-12 16:14:24 UTC
This is my first time posting here so I noticed markdown doesn't work here, so make sure to leave the ` out, i.e., regular expression entered should be:

(?<=Phrase A: ).*[\r\n]+\KPhrase A: 

Make sure to leave a space at the end of the line after A:
Comment 2 Kåre Särs 2025-03-13 06:56:30 UTC
I can reproduce this both with the plugin and the built-in search.

Those lookbehind regexps are tricky to get right :(