PreviousNextTracker indexSee it online !

(113/231) 3266019 - Issue replacing start of line match with empty string

With regex enabled, replacing a start of line match with an empty replace string produces odd results. It appears to try and rematch the same line after performing the replace.

Examples (all with an empty replace string and text AABBA):

Search: ^.
Expected: ABBAA
Result: [blank line]

Search: ^A
Expected: ABBAA
Result: BBAA

Search: ^AA[^A]*
Expected: AA
Result: [blank line]

Interestingly, EOL matches behave as expected. E.g. the search string .$ will only remove the last character of the line.

Submitted Anonymous - 2011-04-01 - 01:11:16z Assigned nobody
Priority 5 Category search and replace
Status Open Group normal bug
Resolution None Visibility No

Comments

2012-07-11 - 14:41:34z
daleanson
Test case 1 steps:

1. new buffer, type in AABBA
2. Search - Find, see search and replace dialog
3. check Keep dialog, Regular expressions, uncheck Ignore case, HyperSearch, Whole word
4. In Search for box enter ^.
5. Click Find button, see the first A in AABBA is selected. This is correct.
6. Click Replace & Find, see buffer now contains ABBA and the first A is again selected. This is correct.
7. Click Replace & Find, see the buffer now contains BBA and the first B is selected. This is correct.
8. Click Replace & Find, see the buffer now contains BA and the first B is selected. This is correct.
9. Click Replace & Find, see the buffer now contains A and the A is selected. This is correct.
10. Click Replace & Find, see the buffer is now empty. This is correct.
11. Repeat steps 1 - 4.
12. Click Replace All, see the buffer is now empty. This is correct.

Test case 2 steps:

1. new buffer, type in AABBA
2. Search - Find, see search and replace dialog
3. check Keep dialog, Regular expressions, uncheck Ignore case, HyperSearch, Whole word
4. In Search for box enter ^A
5. Click Find button, see the first A in AABBA is selected. This is correct.
6. Click Replace & Find, see buffer now contains ABBA and the first A is again selected. This is correct.
7. Click Replace & Find, see the buffer now contains BBA. This is correct.
8. Repeat steps 1 - 4.
9. Click Replace All, see the buffer now contains BBA. This is correct.

Test case 3 steps:

1. new buffer, type in AABBA
2. Search - Find, see search and replace dialog
3. check Keep dialog, Regular expressions, uncheck Ignore case, HyperSearch, Whole word
4. In Search for box enter ^AA[^A]
5. Click Find button, see the AAB in AABBA is selected. This is correct.
6. Click Replace & Find, see buffer now contains BA. This is correct.
7. Repeat steps 1 - 4.
9. Click Replace All, see the buffer now contains BA. This is correct.
2012-07-12 - 00:19:35z
swetha1910
In your test case 1, when 'Replace All' is clicked, the buffer is emptied. But generally when it is clicked , only the first letter should be replaced and when clicked again the next letter should be replaced. But here the entire buffer is emptied, it simply means that the replace all method is called repeatedly.
Example:
Sample input text is:
AABBA
ABBAA
BTLJLD
QWERTY

Search pattern: ^.
Expected Output when Replace All is clicked:
ABBA
BBAA
TLJLD
WERTY

But what happens actually: Buffer is empty.

2012-07-19 - 16:17:47z
k_satoda
Reopened, as the expected behavior is clarified on a discussion on
jedit-devel.
http://jedit.9.n6.nabble.com/jEdit-devel-jedit-Bugs-3266019-Issue-replacing-start-of-line-match-with-empty-string-tp4999689p4999696.html
Here are some essnetial quotes from the discussion:
> FYI, the manual says:
>> Clicking Replace & Find will perform a replacement in the current
>> selection and locate the next occurrence of the search string. Clicking
>> Replace All will replace all occurrences of the search string with the
>> replacement string in the current search scope (which is either ...).
> http://www.jedit.org/users-guide/search-replace.html#d0e3617
...
> There are two different, but both possible, interpretation of the
> "all occurrences":
> A: All occurrences which appear on repeated Replace&Find.
> B: All occurrences which would given by a hypersearch (find all).
> You expect A, I and other two users expect B.

Attachments