Menu

#3529 Issue replacing start of line match with empty string

normal bug
closed-invalid
nobody
5
2018-08-07
2011-04-01
Anonymous
No

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.

Discussion

  • Dale Anson

    Dale Anson - 2012-07-11

    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.

     
  • Dale Anson

    Dale Anson - 2012-07-11
    • status: open --> closed-invalid
     
  • Swetha

    Swetha - 2012-07-12

    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.

     
  • Kazutoshi 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.

     
  • Kazutoshi Satoda

    • status: closed-invalid --> open
     
  • Dale Anson

    Dale Anson - 2018-08-07
    • status: open --> closed-invalid
     
  • Dale Anson

    Dale Anson - 2018-08-07

    Closing as invalid. The patch that was submitted to fix this issue was rejected (https://sourceforge.net/p/jedit/patches/440/). Also, it is easy enough to write a regex that will replace (or in this case remove) just the first character of all lines:

    Open search and replace dialog
    Search for: ^.{1}(.*)?$
    Replace with: _1
    Check "Return value of a BeanShell snippet"
    Click Replace All

     

Log in to post a comment.