Script with regex worked in RJ TextEd 8.65 but fails in 8.70

Ask questions about how to create a script or swap scripts with other users.
Post Reply
dustwalker
Posts: 25
Joined: 08 Jun 2011 17:14

Script with regex worked in RJ TextEd 8.65 but fails in 8.70

Post by dustwalker »

Hi,
I have three Pascal scripts that include the following line:

Code: Select all

Document.ReplaceAll(#13#10+#13#10+'(\r\n)+',#13#10+#13#10,False,False,False,True);
The purpose of this line is to replace three or more consecutive carriage returns for just two carriage returns.

In RJ TextEd 8.65 (and in earlier versions), I activated the "regex search button" and made a dummy search. Afterwards, I could run scripts containing simple regular expressions (I didn't try anything complicated).

I have updated RJ TextEd to version 8.70. Now, regex-containing scripts work even I had not made a previous regex search. Good, thanks. However, this line fails. What is wrong?

Postdata: I realize that the line looks weird. Sometimes carriage return plus line feed is written as #13#10, but another time is written as \r\n. I just tried several combinations until one of them worked.

Congratulations for a great program and best regards

User avatar
pjj
Posts: 1784
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Script with regex worked in RJ TextEd 8.65 but fails in

Post by pjj »

Without any "activation through search" this works for me on the newest version of RJ TE:

Code: Select all

Document.ReplaceAll("[\r\n]{3,}", "\r\n\r\n", false, false, true, true);
and, should you prefer to be a tad more verbose, this:

Code: Select all

var s;
s = Document.Text;
s = ScriptUtils.WRegexReplaceAll(s, "[\r\n]{3,}", "\r\n\r\n");
Document.Text = s;
The only issue I have with the latter snippet is that additional newline is inserted at the end of text. Please notice that you set the penultimate argument of Document.ReplaceAll() to false, while it should be true, since it stands for bRegExp ;) Even if I change this, though, your code ("#13#10") still doesn't work for me.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus

dustwalker
Posts: 25
Joined: 08 Jun 2011 17:14

Re: Script with regex worked in RJ TextEd 8.65 but fails in

Post by dustwalker »

Thanks,
As soon as I corrected the penultimate argument of Document.ReplaceAll() the script line worked. I have replaced it by your own line, however, because your line is neater.

Note: I replaced your line's double quotes by single quotes, because my script syntax is Pascal.

Best regards

User avatar
pjj
Posts: 1784
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Script with regex worked in RJ TextEd 8.65 but fails in

Post by pjj »

dustwalker wrote:I have replaced it by your own line, however, because your line is neater.
Thanks! :) I'm glad I could help.
dustwalker wrote:Note: I replaced your line's double quotes by single quotes, because my script syntax is Pascal.
I know ;)
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus

Post Reply