Some simple text as follows: `A regular expression search.` When using the search and replace in Kate with a regular expression that contains nested lookahead assertions like: `re(?=g|s(?!s))` and attempt to replace it with: `te` it successfully locates "re", but fails to perform the replacement. I try this expression in VSCode and other editors, however, results in a successful replacement to: `A tegular expression search.` This problem seems to show in the latest few versions.
By the way, lookbehind also seems to have the same issue, as I try to search: (?<=g|e(?!s))g and replace it with "x". Just cannot get the correct result as: A rexular expression search.
I can confirm that we have a problem here... The problem seems to be that the text range that we store, to prevent replacing already edited text, does not contain the lookahead/behind. And since that then does not match with the regular expression, it bails out. Now the question is how do we solve the problem? How do we get enough context around the saved range? A single character (or fixed N), would be doable, but that does not scale very much. And rechecking the whole while line might be problematic. what if we have multiple matches on the same line. Which should we replace? One solution could be to strip the lookahead/behind for the replacement validity check regex..., but then if the text around the match has changed to no longer match the original regex, we get a wrong replacement... I need more ideas...
And it turns out we already try to remove the lookahead/behind part of the regex, but it fails to detect the nested stuff
(In reply to Kåre Särs from comment #3) > And it turns out we already try to remove the lookahead/behind part of the > regex, but it fails to detect the nested stuff I try to replace it with the Ctrl+R "search & replace", and it can successfully do the replace. This problem occurs only in the "search & replace" from the bottom menu. I don't know all the detail differences between these two types of search, but I think they should output the same result, as the latter one can provide a nice-looking preview.
Git commit f65aa3e8766324ee297b167e42b84d0c0bd73270 by Kåre Särs. Committed on 26/12/2024 at 18:51. Pushed by sars into branch 'master'. S&R: Handle also complex lookahead and lookbehind When we are safety-comparing the match range to the regexp, remove also a bit more complex lookahead/lookbehind with nested parenthesis M +31 -3 addons/search/MatchModel.cpp M +24 -0 addons/search/autotest/input/LookaheadLookbehindTestFile.txt https://invent.kde.org/utilities/kate/-/commit/f65aa3e8766324ee297b167e42b84d0c0bd73270