Bug 409642

Summary: regex
Product: [Applications] kate Reporter: ch-hamburger
Component: searchAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED INTENTIONAL    
Severity: normal CC: christoph, kare.sars
Priority: NOR    
Version First Reported In: 17.12.0   
Target Milestone: ---   
Platform: Kubuntu   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description ch-hamburger 2019-07-09 06:57:06 UTC
Suppose I want to replace "f{x}" by "f{y}".

I use the regex replace command in Kate with the entries:

Find: \{x

Replace: \{y

But I end up with "f{xy}" instead of "f{y}".
Comment 1 Kåre Särs 2019-07-09 10:11:44 UTC
Is this the built-in search or the search plugin?

In the plugin you do not need to escape '{' in the replace
Comment 2 ch-hamburger 2019-07-09 10:43:56 UTC
This is the built-in search.

In the 'Find' entry the escape of '{' is a must.

In the 'Replace' entry the expected result is obtained by NOT escaping the '{'. But it is not the idea that 'Find' and 'Replace' should require different regex code.
Comment 3 Dominik Haumann 2019-07-10 06:41:27 UTC
The replace part only supports references like \0, \1, ... Indeed, you should not escape anything else.

Maybe we should investigate more, but if you get the correct behavior without \, then this issue is minor.
Comment 4 ch-hamburger 2019-07-11 13:24:37 UTC
The problem may be minor, though it is illogical that 'Find' and 'Replace' should behave differently.

But one or two explanatory lines in the manual, of which you are co-author, would do no harm. :)
Comment 5 Christoph Feck 2019-07-25 09:32:52 UTC
New information was added; changing status for inspection.
Comment 6 Christoph Feck 2019-07-25 09:33:22 UTC
Changing status.
Comment 7 Christoph Cullmann 2019-08-24 15:06:56 UTC
Hmm, the thing is:

The search part of the find and replace is a regex.
The replacement part is a string, with for regex the capture \xxx escapes.

In my eyes it makes no sense to force people to escape their replace strings like an regex for no good reason.

At the moment, you can just write (if regex on or not).

find: XXX
replace: lala{dddd}

I don't think we want to enforce that { needs to be escaped in the replace string if we turn on regex search.

Therefore I would like to keep it as it is.
I hope that is ok for you.