Page 1 of 1

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

Posted: 05 Oct 2013 21:58
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

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

Posted: 06 Oct 2013 12:23
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.

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

Posted: 06 Oct 2013 16:43
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

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

Posted: 06 Oct 2013 17:48
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 ;)