I have a JSON file in VSCode.
I want to replace all hyphens in the document with underscores but only where the same line contains the text: "product":
For example:
{
"product": "replace-my-hyphens",
"label": "do-not-replace-my-hyphens"
}
I have a JSON file in VSCode.
I want to replace all hyphens in the document with underscores but only where the same line contains the text: "product":
For example:
{
"product": "replace-my-hyphens",
"label": "do-not-replace-my-hyphens"
}
2
Answers
what to do:
"product":
Ctrl+Shift+L
)Shift+End
Ctrl+F
-
and (replace)_
Esc
leave multi cursor modeYou can do this with a simple find and replace:
Find:
(?<="product":.*?)-
Replace:
_
As you can see, any
-
will be matched that is preceded by"product":
and some number of characters (except line terminators).See regex101 demo.
This works in a find within one file (i.e., using the Find Widget) but will not work in a Search across multiple files because of the non-fixed length lookbehind.