jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.79k stars 5k forks source link

`Find and Replace` / `Use Regular Expressions` / `Replace All`: reference groups are NOT handled correctly #7503

Open kuraga opened 1 month ago

kuraga commented 1 month ago

Description

On Find and Replace, using Regular Expressions, using Replace All, reference groups are NOT handled correctly.

Reproduce

  1. Create a Jupyter notebook.
  2. Type in the first cell:
    {
    'var1': 123,
    'var2': 456,
    }
  3. Open the Find and Replace dialog.
  4. Roll out the Replace part.
  5. Click the Use Regular Expressions button.
  6. Type: : (\d+), at the Find input.
  7. Type: : $1+1, at the Replace input.
  8. Click the Replace All button.
  9. Expected cell content:
    {
    'var1': 123+1,
    'var2': 456+1,
    }
  10. Actual cell content:
    {
    'var1': $1+1,
    'var2': $1+1,
    }

At the same time, the Replace-button single replaces work as expected.

Expected behavior

On Find and Replace, using Regular Expressions, using Replace All, reference groups are handled correctly.

Context

krassowski commented 1 month ago

I can reproduce this. Using "Replace" button it works as expected, using "Replace All" it does not. FYI this is implemented in JupyterLab repo here:

https://github.com/jupyterlab/jupyterlab/blob/9cc6267d2e366390b861f725e5eca3ae04e86de9/packages/codemirror/src/searchprovider.ts#L399-L436

and replacing a single match is here:

https://github.com/jupyterlab/jupyterlab/blob/9cc6267d2e366390b861f725e5eca3ae04e86de9/packages/codemirror/src/searchprovider.ts#L330-L352

I do not immediately see where the error is. It would be good to also attempt reproducing in JupyterLab 4.3/Notebook 7.3 once these are released (soon).

krassowski commented 2 weeks ago

Heads up: the upstream issue was closed (https://github.com/jupyterlab/jupyterlab/issues/16925) and fixes will be backported to 4.3.x

kuraga commented 2 weeks ago

Ok, thanks!