0

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.

leo
  • 8,106
  • 7
  • 48
  • 80
twirlyman
  • 3
  • 2
  • For the answers below only "Replace all" works in Notepad++. At least in v6.8.1 of Notepad++. There is a v6.8.2 out since August 2015 that I need to try. I am referring to the answers by anubhava and Erutan409. – twirlyman Nov 30 '15 at 20:08
  • Anubhava answered my exact question. Erutan409 went a step further. I really appreciate both answers! They will help in many situations on Wikipedia. I will pass on the info there. – twirlyman Nov 30 '15 at 20:14
  • This discussion has been linked to from [this Wikimedia how-to page](https://commons.wikimedia.org/wiki/Commons:Convert_tables_and_charts_to_wiki_code_or_image_files). For more ideas on this and related topics go there. Some of this info was copied and further developed there. See the section called "Quickly link long lists of countries" (or similar heading). – twirlyman Dec 01 '15 at 12:00

2 Answers2

0

You can use this regex to get first || in each line:

^.*?\K\|\|

\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match

Make sure to use MULTILINE mode.

RegEx Demo

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I am a newb at regex. In Notepad++ I see that `^.*?\K\|\|` finds the first double bars in each line. But I can not figure out how to get Notepad++ to replace them with `]]||` – twirlyman Nov 30 '15 at 19:05
  • I am on OSX so can't answer that unfortunately but my guess is that it should be placed in replacement text field. Press `ctrl-H` and enter above regex in `Find` and enter `\]\]\|\|` in replacement. – anubhava Nov 30 '15 at 19:18
  • That did not help in Notepad++. Nothing in the replacement field is being entered into the wikitext. In the [RegEx Demo](https://regex101.com/r/eY9jE5/1) all I need to put in the replacement field is `]]||`. I see that the g and m modifiers are essential in that demo. When they are deleted at the top right, then nothing is replaced. – twirlyman Nov 30 '15 at 19:41
  • I figured out the problem in Notepad++. Only "Replace all" works. "Replace" does not work. Bizarre. I have v6.8.1 of Notepad++. I see that there is a v6.8.2 out since August 2015. Maybe that will fix the problem. – twirlyman Nov 30 '15 at 19:58
0

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

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

enter image description here

Erutan409
  • 730
  • 10
  • 21
  • Thanks! This works great after I figured out that only "Replace all" works in Notepad++. At least in v6.8.1 of Notepad++. There is a v6.8.2 out since August 2015 that I need to try. – twirlyman Nov 30 '15 at 20:02
  • Very welcome. If this was the final answer that solved your problem, would you mind giving an 'Accepted Answer'? – Erutan409 Nov 30 '15 at 20:10
  • For others reading this: Brackets are added around both ends of country names. Including country names consisting of more than one word. And it only does this in the first cell of each row. In other words the country names before the first set of double bars. This is very useful on Wikipedia. – twirlyman Nov 30 '15 at 20:27