I am trying to search and replace in VS code thousands of instances, etc.
Sample String:
[[123|123]] and [[4567|4567]], also [[89|89]].
Finding [[.*|(.*)]]
and replacing with [[$1]]
. It finds [[123|123]] and [[4567|4567]], also [[89|89]]
turns the whole string into [[123]].
. The values inside the brackets could be any length of characters, but the pipe does separate them.
I tried anchoring start and end with ^[[.*|(.*)]]$
, but then nothing matched.
Wanted result:
[[123]] and [[456]], also [[789]].
2
Answers
I found the answer, but I don't know why it works. I was just continuing to play and found that this works for the search:
If you want to find anything in between the brackets ([[ ]]), you need to filter for any character, which is not
]
instead of any character (.
).If not it will select the whole string.
[^t]*
= is every character exceptt
[^]]*
= is every character except]
So try
[[[^]]*]]
as regexEven if this does not solve your problem fully, it hopefully will give you the idea.