In Visual Studio Code, in replace, I want to refer to what found in search with regex.
I thought this was done with $1
, $2
, etc. but I could not.
then:
What I want to achive is to get:
How can I refer in replace to what is found in search?
Note:
What I really aim is not the one in this example. It is only an example to explain what I need: refer to what is found. So, please don’t mind offer other ways to replace "spaces with ->"spaces<-.
2
Answers
You can do this using the same syntax but in the search bar (Ctrl+Shift+F).
edit: I was able to refer to the group this way:
example
In your example, nothing is "found" because you don’t make use of any capture groups in your pattern.
If you need to refer to the whole match, use
$0
in theReplace
field.If you really want to use
$1
instead for whatever reason, wrap your pattern inFind
with parenthesis()
to indicate it should be treated explicitly as a capture group.