You are here: PSPad forum > English discussion forum > Re: Regex replace not working across broken lines

Re: Regex replace not working across broken lines

#1 Regex replace not working across broken lines

Posted by: therium | Date: 2015-12-20 16:32 | IP: IP Logged

PSPad 4.5.9 (2600) on Win 7.

If I have input like this, where <CR> is a carriage return:

This is a test.^1<CR>
<#fn1>

And I use this search and replace:

Search: \^(\d+)\s+<#fn\d+>

Replace: \[\^$1\]

Basically, I want to replace '^1 <#fn1>' with '[^1]'.

PSPad will not find the string because of the embedded CR, even though \s includes tab, space, and carriage returns \l and \n. Am I not understanding something? Because this works fine in the online regex tester regex101.com.

However the Regex tester allows the 'g' switch, while PSPad does not. Perhaps that makes a difference.

I'm also having this problem replacing slashes with a single star(*). If the second slash is on a different line, PSPad simply does not find it.

Input: /This is a broken line<CR>
that continues on the next line./

Thank you for clearing this up for me. This is actually a common occurance in the files I'm dealing with.

Edited 2 time(s). Last edit at 2015-12-20 16:40 by therium.

Options: Reply | Quote | Up ^


#2 Re: Regex replace not working across broken lines

Posted by: vbr | Date: 2015-12-20 21:21 | IP: IP Logged

Hi,
unfortunately, this is one limitation of the searching implementaion in PSPad (that might be enhanced in future).
Searching works on individual lines rather than on the whole text at once, hence the match cannot cross the newline boundary, as your pattern would require.
There are some workarounds in the current state, including scripting within PSPad, but there are specific downsides too.

regards,
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