Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex replace issue with \K when replacing with a group #5350

Closed
Ahmed-Abdelhameed opened this issue Feb 27, 2019 · 2 comments
Closed

Regex replace issue with \K when replacing with a group #5350

Ahmed-Abdelhameed opened this issue Feb 27, 2019 · 2 comments

Comments

@Ahmed-Abdelhameed
Copy link

Description of the Issue

I just encountered a strange regex behavior when using \K and replacing with a matching group. Let's say we have this string aaa bbb ccc and we use the pattern aaa\K bbb (ccc) and replace with \1, the expected behavior would be to replace bbb ccc with ccc returning aaaccc; that actually works as expected. Now let's try the same pattern when multiple matches are expected (i.e., input string = aaa bbb ccc aaa bbb ccc), in that case, the replacing has no effect whatsoever (my guess is that it replaces with the full match instead of the provided group).

Steps to Reproduce the Issue

  1. In a new/empty file, add the following text:

    aaa bbb ccc aaa bbb ccc

  2. Open the "find & replace" dialog and set the search mode to "Regular expression".
  3. Type aaa\K bbb (ccc) in the "Find" field and \1 in the "Replace field".
  4. Click "Replace" (not "Replace all").

Expected Behavior

Each aaa bbb ccc string should be replaced with aaaccc.

Actual Behavior

Nothing is replaced and the matches stay the same. Note: as mentioned above, there has to be more than one match in order to reproduce the issue.

Debug Information

Notepad++ v7.6.3 (32-bit)
Build time : Jan 27 2019 - 17:20:30
Path : C:\Program Files (x86)\Notepad++\notepad++.exe
Admin mode : ON
Local Conf mode : OFF
OS : Windows 7 (64-bit)
Plugins : DSpellCheck.dll mimeTools.dll NppConverter.dll NppExport.dll

Screenshot:

Screenshot

@sasumner
Copy link
Contributor

This will be of course NOT what you want to hear, but it is VERY-long-known that \K in a regex in Notepad++ does not work correctly (in most cases) unless you use "Replace All". Can it be fixed? Sure, pretty much all software problems can be fixed. The bigger question is Will it ever be fixed?

@sasumner
Copy link
Contributor

Duplicate of the more-recent #8434 , so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants