Home > Enterprise >  Find & Replace Markdown Image in VSCode using Regex?
Find & Replace Markdown Image in VSCode using Regex?

Time:10-25

I have lots of markdown files with 100 images referenced inside it.

I'm looking for a way to find & replace them.

It should remove the caption of the image & the last part of image should be appended with {width=100%}

![a caption](./img.png)

should be replaced with

![](./img.png){width=100%}

How do I do it in VSCode?

I have found the regex for image is !\[[^\]]*\]\((.*?)\s*("(?:.*[^"])")?\s*\) but don't know how to move forward?

The only thing I could figure out was appending {width=100%} in the replace input.

Currently, my find input looks like:

!\[[^\]]*\]\((.*?)\s*("(?:.*[^"])")?\s*\)

And replace input looks like:

!\[[^\]]*\]\((.*?)\s*("(?:.*[^"])")?\s*\){width=100%}

CodePudding user response:

I found the answer while reading an answer in another tab.

find: !\[[^\]]*\]\((.*?)\s*("(?:.*[^"])")?\s*\)
replace: ![]($1){width=100%}
  • Related