You are here: PSPad forum > Bug report / Hlášení chyb > Re: Issue with regex search and replace when using \n in replacement string

Re: Issue with regex search and replace when using \n in replacement string

#1 Issue with regex search and replace when using \n in replacement string

Posted by: jojo | Date: 2024-06-01 13:16 | IP: IP Logged

I'm using the latest dev version 815, but also in earlier versions. There is an issue when using regex-bases search and replace when using the newline character (\n) in the replacement string. The replacement itself works as intended, but the number of internal undo steps explodes and as a result the action may not be able to undo in its entirety.

Steps to reproduce:

1. Put the following text into a text file:

1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0

2. Open Find and Replace, set mode to regex, search for " " (space character), replace with "\n" (newline).

3. Observe the result: As intended, all the digits are now put on individual lines. But the following error message is shown:

Quote:
Searched expression " " was replaced 4095x times.
Can't Undo all replacements, because not enough Undo steps

The problem gets worse if you repeat the pattern from step 1 a few more times, at some point undo will just not work sensibly anymore.

Options: Reply | Quote | Up ^


#2 Re: Issue with regex search and replace when using \n in replacement string

Posted by: vbr | Date: 2024-06-04 11:56 | IP: IP Logged

jojo:
I'm using the latest dev version 815, but also in earlier versions. There is an issue when using regex-bases search and replace when using the newline character (\n) in the replacement string. [...]

Hi,
there is currently a technical limitation of PSPad in searching/replacing newlines.
In some cases like this one a workaround can help - You can set backwards search direction, after placing the cursor at the end of the file.

In this case it results in the expected number of replacements and there are no problems with undo history, but it is somehow less convenient.

hth,
vbr

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR