You are here: PSPad forum > Bug report / Hlášení chyb > Regular Expressions Replace
Posted by: carbonize | Date: 02/03/2010 13:13 | IP: IP Logged
It appears that using regular expressions in a replace is not working any more.
I created a blank text file containing
1
2
3
4
5
6
7
Then I placed the cursor at the end and tried both a search and replace with it set to go backwards. It failed to find \n and I even tried \n\r and just \r
--
Carbonize
Posted by: pspad | Date: 02/03/2010 13:21 | IP: IP Logged
Use Join lines from menu Edit / Lines manipulation
Posted by: carbonize | Date: 02/03/2010 13:30 | IP: IP Logged
That was just an example. I had a txt file in which some words had been split using a hyphen like
sudden-
ly
So I needed to use the regex -\n to remove them all but it doesn't work any more.
--
Carbonize
Posted by: carbonize | Date: 02/16/2010 17:58 | IP: IP Logged
Yes I have since installed it after speaking to MrSpock and vbr. Still doesn't fully support the regex I was hoping to use but such is life.
--
Carbonize
Posted by: vbr | Date: 02/16/2010 21:53 | IP: IP Logged
carbonize:... Still doesn't fully support the regex I was hoping to use but such is life.
What kind of pattern would you need to use?
Chances are, it might be don with a custom script (well, unless you need some feature not supported in JavaScript or VBScript).
If I remember correctly, there was some special behaviour of matching newlines in phReplace, but in the multiline fields, you can usually insert a real linebreak in the pattern, in case \n wouldn't work.
vbr
Posted by: massimobalestra | Date: 02/18/2010 22:44 | IP: IP Logged
I have a similar problem.
I have a string like:
progr "par1=1" "par01=01" "par02=02" "par03=03" "par04=04" "par05=05" "par06=06" "par07=07" "par08=08" "par09=09" "par10=10" "par11=11" "par12=12" "par13=13" "par14=14"
(all in one line)
I would like to see the parameters by line, one on each line.
I wanted to use the replace:
search: '" "'
replace: '"\n"'
And it des not work. It does the first and then stop. If I restart the replace with the same parameters it does another and then stop.
I guess it is a bug only if the regular expression is checked.
Thank you
Massimo
Posted by: vbr | Date: 02/19/2010 00:45 | IP: IP Logged
massimobalestra:I wanted to use the replace:
search: '" "'
replace: '"\n"'And it des not work. It does the first and then stop.
...
This the easier part of the problem, which can be worked around:
Place the cursor at the end of the text a preform the above re replacement in the backwards direction.
On the other hand, you cannot replace the newline characters itself with the built in engine, but it is possible in the mentioned script like phReplace.
hth
vbr
Posted by: carbonize | Date: 02/19/2010 11:06 | IP: IP Logged
I basically had a file like
Quote:alpha bravo charlie
delta echo foxtrot golf.abacus banana
condor.uno dos tres.
my aim was to make all the sentences in to a single line by removing the \n but keep the empty lines. I think anyway as I forget now. I tried various regex such as
[a-zA-Z0-9-]\n[a-zA-Z0-9-] (finds nothing)
\w\n\w (again finds nothing)
\W\n\W
and I started at the end with it set to work backwards. None of it seemed to work as I expected. Basically I think the regex in it is either not complete or broken since using \W should only select non word characters and \w is word characters (letters, digits and underscores).
Maybe I'm just to tired and making a total balls up of it. The outcome after the replace should be
Quote:alpha bravo charlie delta echo foxtrot golf.abacus banana condor.
uno dos tres.
--
Carbonize
Posted by: vbr | Date: 02/21/2010 21:35 | IP: IP Logged
carbonize:...
my aim was to make all the sentences in to a single line by removing the \n but keep the empty lines. ...
Hi, in phReplace you probably could use a re replacement
([^\r\n])\r\n([^\r\n])
with
$1$2
(in my Poor Man's RE it would be the equivalent
/([^\r\n])\r\n([^\r\n])/g, "$1$2"
With built in PSPad functions you cannot search for the linebreak \n directly; approximately the same result would involve multiple steps:
relace (regexp):
^$
QQQQ (or any other separator string otherwise NOT present in the text)
Edit :: Lines manipulation :: Join lines
Backwards re replace:
QQQQ
with
\n
(possibly fix the starting spaces inserted by "join lines").
vbr
Editor PSPad - freeware editor, © 2001 - 2013 Jan Fiala
Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák