You are here: PSPad forum > Bug report / Hlášení chyb > Regex search&replace with newline does not work as intended

Regex search&replace with newline does not work as intended

#1 Regex search&replace with newline does not work as intended

Posted by: jojo | Date: 2018-01-30 14:59 | IP: IP Logged

Given the following text: "a | b | c | d"
Search for: \|
Replace by: \n|

In the latest stable version, around 16000 newlines are inserted after "a" until PSPad gives up and tells me the regex is not formatted correctly.
In the latest development version, I can observe two behaviours. Either the replaced document looks like this:
"a
| b | c | d"
PSPad tells me that the expression was replaced three times, although obviously it was only replaced once.

Or, if it search for "|" instead of "\|", I get:
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|a | b | c | d"
PSPad tells me the expression was replaced 14 times.

All three behaviours obviously do not deliver the expected outcome, which is:
"a
| b
| c
| d"

Edited 1 time(s). Last edit at 2018-01-30 14:59 by jojo.

Options: Reply | Quote | Up ^


#2 Re: Regex search&replace with newline does not work as intended

Posted by: vbr | Date: 2018-01-30 15:47 | IP: IP Logged

jojo:
Given the following text: "a | b | c | d"
Search for: \|
Replace by: \n|

In the latest stable version, around 16000 newlines are inserted after "a" until PSPad gives up and tells me the regex is not formatted correctly.
In the latest development version, I can observe two behaviours. Either the replaced document looks like this:
"a
| b | c | d"
PSPad tells me that the expression was replaced three times, although obviously it was only replaced once.

Or, if it search for "|" instead of "\|", I get:
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|a | b | c | d"
PSPad tells me the expression was replaced 14 times.

All three behaviours obviously do not deliver the expected outcome, which is:
"a
| b
| c
| d"

Hi,
handling newlines in search and replace functions is indeed a bit restricted and sometimes unintuitive in PSPad, but in this case a workaround can be used: If you place the cursor at the end of the text and set the search direction backward (in the respective dialog), your original pattern works:
Search for: \|
Replace by: \n|

the result is:

a
| b
| c
| d

hth,
vbr

Options: Reply | Quote | Up ^


#3 Re: Regex search&replace with newline does not work as intended

Posted by: Andreas | Date: 2018-01-30 15:58 | IP: IP Logged

In PSPad I always do this with the phreplace addon.

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