SteGriff

Blog

Next & Previous

Regex replace in Notepad++

I just went through and fixed up a load of old markdown on this blog. I used to float images to the right, so if I wanted an image “in block flow”, I had to use HTML to make it float none. Well, now all images are in block flow, so I can remove those hacks.

I did a global search in my md files for “fn” and found all the offending documents.

Needed to remember how to do a regex replacement in Notepad++ and change every occurence like

<img class="fn" alt="Clicking on new repository" src="/assets/github-pages/newrepo.jpg">

into

![Clicking on new repository](/assets/github-pages/newrepo.jpg)

tl;dr - the regex

Find: <img class="fn" alt="([A-Za-z0-9 ]+)" src="([A-Za-z0-9 \/\-.]+)">

Replace: ![\1]\(\2\)

Two capture groups, \1 and \2 are created, using parentheses. The first captures alphanumeric and spaces ([A-Za-z0-9 ]+), the second captures kebab-case file names: ([A-Za-z0-9 \/\-.]+). The rest of the string is pretty static. Could have used a regex in the class field but didn’t need to.

Replacement uses the markdown image syntax and pipes in the captured alt text and image source.

Sample text - before

Open GitHub in your browser, login (or make an account and login) then go to New Repository

<img class="fn" alt="Clicking on new repository" src="/assets/github-pages/newrepo.jpg">

Enter some details for the repository and click on Create - you don't need to initialise it with any files.

<img class="fn" alt="Setting up a new repository" src="/assets/github-pages/createrepo.jpg">

Result

Open GitHub in your browser, login (or make an account and login) then go to New Repository

![Clicking on new repository](/assets/github-pages/newrepo.jpg)

Enter some details for the repository and click on Create - you don't need to initialise it with any files.

![Setting up a new repository](/assets/github-pages/createrepo.jpg)