Search code examples
regexnotepad++wikitext

Notepad++. Need to add brackets before only first occurrence of characters in lines


Please see the Wikipedia article "List of countries by total health expenditure per capita". The countries listed in the long table should all be links. That means in the wikitext the country names need double brackets around them. For example; [[Australia]] - This is a common problem when creating country lists.

I pasted the wikitext into Notepad++. I know how to add brackets in front of the country names. There are some unique characters and line breaks that allow me to use basic find and replace (no need for regular expressions).

But I can not figure out how to add brackets after the country names. There is a set of double bars after each country name. But unfortunately, there are multiple sets of double bars in each line. See some of the wikitext:

|-
|Australia||3866||..||..
|-
|Austria||4528||4553||..
|-
|Belgium||4225||4256||..

So I need a way to only find the first set of double bars in each line, and then add brackets in front of them.


Solution

  • I forked anubhava's regex demo and created this regex, instead:

    ^.*?\|\h*\K(.*?)(?=\h*\|) replace with [[$1]]

    enter image description here