![How to replace all links in html to markup](/images/2021/09/replace_huc838aad17fd268f95e587bce890f3d10_222013_640x0_resize_box_3.png)
How to replace all links in html to markup
Regular expression to replace href to markup
I recently moved my blog from WordPress to Hugo , which involved a lot of content fixing. One of the problems was that not all HTML code was correctly transferred to markup during the export. So I needed fix (replace) all pending <a href="https://spidersoft.com.au">spidersoft</a> to [spidersoft](https://spidersoft.com.au).
What we need are just two simple regular expressions.
One to find links <a.*?href="(.+?)".*?>(.+?)</a>
Second one to replace them in reverse order [$2]($1)
You can run this in basically any IDE - Sublime will do the job, I was using PHPStorm