Incorrect Batch Regex Replacement
Opened this issue · 0 comments
snyhai commented
Environment data
- VS Code version: 1.95.3
- Jupyter Extension version (available under the Extensions sidebar): v2024.10.0
- Python Extension version (available under the Extensions sidebar): v2024.20.0
- OS (Windows | Mac | Linux distro) and version: Mac 15.2 Beta (24C5089c)
- Python and/or Anaconda version: Python 3.12.2 conda 24.9.2
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
- Jupyter server running: Local
Expected behaviour
When performing a regex-based batch replacement for the pattern (\d)\+(\d)
with replacement $1 + $2
, all occurrences across cells should be updated consistently.
Input ipynb JSON:
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"3+4\n",
"2+3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"2+3\n",
"1+2\n",
"0+1"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Expected single and batch replacement result:
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"3 + 4\n",
"2 + 3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"2 + 3\n",
"1 + 2\n",
"0 + 1"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Actual behaviour
When performing batch replacement, the second cell’s content is processed incorrectly, resulting in an incorrect update. The output looks as follows:
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"3 + 4\n",
"2 + 3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"3 + 4\n",
"2 + 3\n",
"2 + 3"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Steps to reproduce:
- Use the above input ipynb file.
- Perform regex replacement with pattern
(\d)\+(\d)
and replacement$1 + $2
in the Jupyter notebook. - Compare results for single and batch replacement modes.
Logs
There is no relevant output in the Jupyter panel.
I don’t know whether this is an issue with VS Code or Jupyter, but this kind of error only seems to occur in .ipynb files.