sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

Replacement with negative lookahead impossible

Open WoodrowShigeru opened this issue 1 year ago • 0 comments

Description of the bug

I'm trying to use find and replace with a negative lookbehind regex in order to add a return keyword to a few selected lines. For this, I am using the hotkeys (in safe mode) ctrl+shift+h and f3 to navigate.

I could (and currently have to) use regexes without negative lookbehind, and careful skipping / navigation. Or I could craft a regex (with negative lookbehind) that includes exactly the lines I want, and then "replace all".

The latter methodology is currently inaccessible because of this bug.

Steps to reproduce

  1. Start ST in safe mode.
  2. Paste this content:
use MyApp\Controller\Redirector;

	Redirector::emit(400, $response);
	Redirector::emit(404, $response);
	Redirector::emit(404, $response);
	Redirector::emit(404, $response);
	Redirector::emit(404, $response);
	return Redirector::emit(400, $response);
  1. Skip the import line which we don't want to replace, so place the cursor further down in the document.
  2. Set up find-and-replace.
replace: (?<!return )Redirector
with: return Redirector
regex: on
  1. Try to replace with ctrl+shift+h.

Expected behavior

Same behavior as with any regex that doesn't use negative lookbehind.

  • If current selection doesn't match then jump to the next line (next = down) that matches.
  • If current selection does match then replace it, regardless of whether it's the first match of the file.

Actual behavior

  • If current selection doesn't match then jump up to a previous line that matches.
  • If current selection does match but it's not the first match of the file, then jump up to the previous match.
  • If current selection does match and it's the first match of the file then replace it.

Sublime Text build number

4169

Operating system & version

Ubuntu 18.04.6 // also Ubuntu 22.04.3

(Linux) Desktop environment and/or window manager

No response

Additional information

Maybe this bugfix https://github.com/sublimehq/sublime_text/issues/2038 broke the behavior. I can't tell for sure.

Compare these replacement regexes:

  • (?<!return )Redirector
  • (?<!return |Controller\\)Redirector
  • \tRedirector

OpenGL context information

No response

WoodrowShigeru avatar Jan 14 '24 18:01 WoodrowShigeru