Bug 127765 - Replace function with regular expression
Summary: Replace function with regular expression
Status: RESOLVED DUPLICATE of bug 45529
Alias: None
Product: kate
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-21 13:23 UTC by Daniel Moyne
Modified: 2008-10-15 17:33 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Moyne 2006-05-21 13:23:58 UTC
Version:           2.5.2 (using KDE 3.5.2, Kubuntu Package 4:3.5.2-0ubuntu0breezy1 breezy)
Compiler:          Target: x86_64-linux-gnu
OS:                Linux (x86_64) release 2.6.12-10-amd64-k8

Let us assume I want to add a tab char in front of all lines starting with "1 " I can search the regular expression "^1 " but then I cannot insert with the Replace field "/tab" as replace cannot use regular expression !

Am I confused if I ask for a regular expression feature for the Replace field or can this be achieved otherwise with the present Kate features ?
Regards.
Comment 1 Matthew Woehlke 2006-05-22 20:00:57 UTC
You want escape sequences to work in the 'replace' field, I think... I'm not sure what meaning a regular expression would have, unless you mean the '&1' syntax (which is all sed supports anyway).

However, there is a easy work-around for tabs... just copy the text you want to use for the replacement, including the tab, and paste into the appropriate box.
Comment 2 Daniel Moyne 2006-05-24 13:20:54 UTC
in Replace filed for me regular expression would of course be only fully determined and not analysed ; it would allow to add TAB, CR and other special characters only ; for example you want to add a CR each time you find a string so in Findf field you have "String" and in Replace filed you have "String$" but apparently this looks strange to you !
Regards
Comment 3 Matthew Woehlke 2006-05-24 16:58:48 UTC
Yes, that looks strange :).

I still think what you want is 'String\n', not 'String$' (which... ok, makes sense in a rather strange way, but isn't as intuitive as '\n'). IOW you want escape sequences like '\t', '\n', etc, to be recognized... As I understand, this would do what you're asking for in a way that is pretty standardized. I fully endorse this, as I also find it somewhat annoying.

Of course, it *could* be really useful if '\[0-9]' were also recognized (apologies for mis-remembering earlier and calling it '&1', the correct syntax is indeed '\1'), and since these already look like escape sequences, they would easily fit into the same functionality.
Comment 4 Daniel Moyne 2006-05-25 14:08:29 UTC
To close this topics do you think it would have some value should we had this feature in the Find & Replace function ; of course the possibility to have regular expression would be much more limited in Replace than in Search and fully determined.

By the way with Search you do not use the regular expression "<String>\n" but "<String>$" !
Comment 5 Matthew Woehlke 2006-05-25 19:14:53 UTC
'info sed'

'$' is a metacharacter that matches the end of a string... if anything, it is equivalent to '\0', not '\n'. However, you *can* match '\n' if your pattern space contains a '\n'. Now, in KATE's F&R, this won't happen, but in sed (which uses the same regular expressions), it might. Similarly, you would not use something like '[A-Z]' in a replacement.

For an interesting experiment, try "echo foo | sed 's/$/\nbar/'" and "echo foo | sed 's/$/$bar/'". You're essentially dealing with the same syntax in F&R, except that ATM the 'replace' field is not parsed but used verbatim. I would think that for consistency, the 'replace' field should be parsed the same way sed would parse it.

But to answer your first question (which I already did in my previous comment), yes I definately think this would be valuable, and I think it *would* be beneficial to eventually support '\1', etc, but the more immediate need seems to be for basic, common escape sequences like '\n' and '\t'.
Comment 6 Daniel Moyne 2006-05-26 13:22:27 UTC
thanks Matthew for all this contribution.

Another point very general : once I suggested to include in the pop up menu on Destop a "Bug report" menu item as as far as I understand you do not know what to do when you want to report a bug or a suggestion related to Desktop itself like this suggestion ! ; could you forward this to the person in charge ; thanks in advance.
Comment 7 Matthew Woehlke 2006-06-13 16:53:32 UTC
So... can someone confirm this? Also, I'd like to re-visit my own comments and go ahead and vote for being able to use ALL escape sequences (i.e. including the regexp '\1', '\2', etc). I just ran into a situation where I really wished KATE had this feature!
Comment 8 Daniel Moyne 2006-06-13 20:14:00 UTC
I raised the point at the beginning ; another thought ; let us assume I want to replace a line by 3 lines then a regular expression for Replace could be "1st_line_string$second_line_string$third_line_string" ; so how to achieve this otherwise ?
Regards
Comment 9 Matthew Woehlke 2006-06-13 20:56:08 UTC
I think you're still confused about the syntax of the replacement string. With escapes being processed, you would use "1st_line_string\nsecond_line_string\nthird_line_string" as the replacement string. This doesn't need support for '\1', etc.

This is also how sed works (and I am still arguing that it should work like sed, since that is more-or-less a standard of regexp processing); if you try something like 's/$/foo$bar$none/' in sed, you would get the text "foo$bar$none" added to the end of every line; NOT 'foo' added to the end of every line and then the lines "bar" and "none" after. Still confused?
Comment 10 fantasai 2006-10-12 19:23:31 UTC
Someone with editbugs permission, please
  - Change the summary to "allow backslash escapes in replace string"
  - Confirm this bug
Comment 11 Matthew Woehlke 2006-10-12 20:41:21 UTC
Seconding #10.

Also, when this is implemented can it be conditional on 'use placeholders' being checked, BUT change 'use placeholders' to 'regular expression' (like above)? This would seem to be most understandable.

And since bugzilla won't let me file against 3.4.x any more (and my attempt to upgrade to 3.5.4 failed), can someone either confirm that 'use placeholders' is REMEMBERED in new versions, or file a new bug?
Comment 12 Matthew Woehlke 2006-12-06 00:53:55 UTC
Ok, it is remembered in 3.5.5. Although I can't seem to use '\0\0' (for example); is that by design?

Maybe it is time to mark this as a duplicate of Bug 45529?
Comment 13 Sebastian Pipping 2007-04-20 14:34:56 UTC
This bug looks like a dup of Bug 45529 to me.
Could someone mark it as a duplicate please?
Seems like I cannot do that myself.
Comment 14 Matthew Woehlke 2007-04-20 16:58:45 UTC
Hmm... ok, done. '\0\0' also seems to be working in branches/3.5 (and hopefully /trunk! :-)).

*** This bug has been marked as a duplicate of 45529 ***
Comment 15 Gudy 2008-10-15 17:25:56 UTC
search an search&replace could never find a linefeed or CR
Comment 16 Sebastian Pipping 2008-10-15 17:33:48 UTC
(In reply to comment #15)
> search an search&replace could never find a linefeed or CR

Sorry, I don't follow.  What do you mean?