Bug 501413

Summary: Find / Replace not working with regular expression
Product: [Applications] kate Reporter: Jacob <chase63790>
Component: searchAssignee: KWrite Developers <kwrite-bugs-null>
Status: CONFIRMED ---    
Severity: normal CC: christoph, kare.sars
Priority: NOR    
Version First Reported In: 24.12.3   
Target Milestone: ---   
Platform: Other   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Sentry Crash Report:

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 :(
Comment 3 Christoph Cullmann 2025-07-20 19:12:23 UTC
Patches welcome to fix that.