Discussion:
"[char]*$" S&R regexp doing double-pass?
Offer Kaye
2009-02-24 14:08:26 UTC
Permalink
Hi,
I'm not sure whether this is a bug or feature.
I first noticed it when using the regexp "\s*$" in the "Find" section
of the "Find and Replace" dialog, and doing a (regexp) replace for
some character, for example ";", I see ";" inserted twice if there are
one or more space characters at the end of the line, instead of just
once (as is the case if there are no spaces).

So if for example I started with:
1
2<space>
3<space><space>
4<space><space><space>

And did the above search/replace, I end up with:
1;
2;;
3;;
4;;

To debug, I tried starting with:
0
1a
2aa
3aaa
4aaaa

And doing S&R for "a*$" to ";". The way I read this is "replace zero
or more instances of the character "a" at the end of the line with
";".
Trying "perl -ne's/a*$/;/;print;' file" with "file" having the above
content gave as expected a single ";" at the end of each line.
However with NEdit S&R, I saw the same behavior as "\s*", namely 2 ";"
if "a" appeared one or more times in the line.

Note BTW that regexp with start-of-line anchor ("^a*" for example) did
not have any such problems.

Best regards,
--
Offer Kaye
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Bert Wesarg
2009-02-24 15:41:51 UTC
Permalink
Post by Offer Kaye
Hi,
Hi,
Post by Offer Kaye
I'm not sure whether this is a bug or feature.
I first noticed it when using the regexp "\s*$" in the "Find" section
of the "Find and Replace" dialog, and doing a (regexp) replace for
some character, for example ";", I see ";" inserted twice if there are
one or more space characters at the end of the line, instead of just
once (as is the case if there are no spaces).
1
2<space>
3<space><space>
4<space><space><space>
1;
2;;
3;;
4;;
0
1a
2aa
3aaa
4aaaa
Can't reproduce with:

NEdit release of Nov 5, 2008

Built on: Linux, x86-64, GNU C
Built at: Feb 24 2009, 16:29:35
With Motif: 2.2.3 [@(#)Motif Version 2.2.3]
Running Motif: 2.2 [unknown]
Server: The X.Org Foundation 10502000
Visual: 24-bit TrueColor (ID 0x25, Default)
Locale: en_US.UTF-8

Which version are you using?

Bert
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Lester M Petrie
2009-02-24 16:09:17 UTC
Permalink
Hi
Post by Bert Wesarg
Post by Offer Kaye
Hi,
Hi,
Post by Offer Kaye
I'm not sure whether this is a bug or feature.
I first noticed it when using the regexp "\s*$" in the "Find" section
of the "Find and Replace" dialog, and doing a (regexp) replace for
some character, for example ";", I see ";" inserted twice if there are
one or more space characters at the end of the line, instead of just
once (as is the case if there are no spaces).
NEdit release of Nov 5, 2008
Built on: Linux, x86-64, GNU C
Built at: Feb 24 2009, 16:29:35
Running Motif: 2.2 [unknown]
Server: The X.Org Foundation 10502000
Visual: 24-bit TrueColor (ID 0x25, Default)
Locale: en_US.UTF-8
Which version are you using?
Bert
I do reproduce this behavior with :

5.6 [Under Development] HEAD
Nov 26, 2007

Built on: Linux, 386, GNU C
Built at: Sep 16 2008, 17:17:19
With Motif: (Untested) 2.3.1 [@(#)Motif Version 2.3.1]
Running Motif: 2.3 [@(#)Motif Version 2.3.1]
Server: The X.Org Foundation 10503000
Visual: 24-bit TrueColor (ID 0x21, Default)
Locale: en_US
--
Lester M Petrie
Oak Ridge National Lab
865-574-5259
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Bert Wesarg
2009-02-24 19:02:10 UTC
Permalink
Ok, don't know what happened last time. This time I can reproduce.

And Joerg your are wrong, unfortunately. It is a forward search&replace.

Bert
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Joerg Fischer
2009-02-24 18:32:50 UTC
Permalink
Post by Offer Kaye
1
2<space>
3<space><space>
4<space><space><space>
1;
2;;
3;;
4;;
0
1a
2aa
3aaa
4aaaa
And doing S&R for "a*$" to ";". The way I read this is "replace zero
or more instances of the character "a" at the end of the line with
";".
...
Note BTW that regexp with start-of-line anchor ("^a*" for example) did
not have any such problems.
What you describe happens by matching in _backward_ direction. Try to search
in forward direction and it behaves correctly. Or you need a non-greedy
start of the pattern, like you noticed.

This is caused by the type of the regex engine implemented into NEdit.
Has to do something with efficiency.

--Jörg
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Joerg Fischer
2009-02-24 18:59:38 UTC
Permalink
Post by Joerg Fischer
What you describe happens by matching in _backward_ direction. Try to search
in forward direction ...
Sorry, I should test first then answer.

No, you're right. There seems to be a problem of how the next
match is found after a replacement. \s+$ works as expected.

(Direction doesn't matter with "Replace all in Window".)

--Jörg
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
AVKuznetsov
2009-02-25 07:17:36 UTC
Permalink
On Tue, 24 Feb 2009 16:08:26 +0200
Post by Offer Kaye
Hi,
I'm not sure whether this is a bug or feature.
I first noticed it when using the regexp "\s*$" in the "Find" section
of the "Find and Replace" dialog, and doing a (regexp) replace for
some character, for example ";", I see ";" inserted twice if there are
one or more space characters at the end of the line, instead of just
once (as is the case if there are no spaces).
.....

Hi,

This bug is reproduced by latest NEdit's code.
Can you make a report to the bugs tracker?

Alexey Kuznetsov
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Offer Kaye
2009-02-26 15:35:28 UTC
Permalink
Post by AVKuznetsov
Hi,
This bug is reproduced by latest NEdit's code.
Can you make a report to the bugs tracker?
Alexey Kuznetsov
Hi,
Added to tracker, new item URL:
http://sourceforge.net/tracker2/?func=detail&aid=2642160&group_id=11005&atid=111005

Regards,
--
Offer Kaye
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Loading...