-2

I would like to get the text in the frame "[[Fichier .... ]]" here in the text :

=== Langues ===
{{Article détaillé|Langues en Afrique du Sud}}
[[Fichier:South Africa dominant language map.svg|thumb|300px| Répartition 
des langues officielles dominantes par région :
{{clear}}
{{legend|#80b1d3|[[Zoulou]]}}
{{legend|#8dd3c7|[[Afrikaans]]}}
{{legend|#fb8072|[[Xhosa (langue)|Xhosa]]}}
{{legend|#ffffb3|[[Anglais]]}}
{{legend|#fccde5|[[Tswana|Setswana]]}}
{{legend|#bebada|[[Ndébélés|Ndebele]]}}
{{legend|#fdb462|[[Sotho du Nord]]}}
{{legend|#b3de69|[[Sotho du Sud]]}}
{{legend|#bc80bd|[[Swati]]}}
{{legend|#ccebc5|[[Venda (langue)|Tshivenda]]}}
{{legend|#ffed6f|[[Tsonga (langue)|Xitsonga]]}}
{{legend|#d0d0d0|Pas de langage dominant}}]]
Il n'y a pas de langue maternelle majoritairement dominante en Afrique du     Sud. Depuis [[1994]], [[Langues en Afrique du Sud|onze langues officielles]]     (anglais, afrikaans, zoulou, xhosa, zwazi, ndebele, sesotho, sepedi, setswana,     xitsonga, tshivenda<ref>[http://www.lafriquedusud.com/ethnies.htm         lafriquedusud.com]</ref>) sont reconnues par la [[Constitution de l'Afrique du     Sud|Constitution sud-africaine]]<ref>{{Ouvrage|langue=fr|auteur1=François-    Xavier Fauvelle-Aymar|titre=Histoire 

How can I improve the following regex:

\[\[Fichier:.*(.*\[\[.*\]\].*)*.*\]\]

In order to match all the liness until the correct ]]?

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264

2 Answers2

-1
\[\[Fichier:(.*?(\n))+.*\]\]

Match all the lines between [[ and ]].

Here is the best sandbox: http://www.regexr.com

eapo
  • 1,053
  • 1
  • 19
  • 40
  • This expression is rather too greedy and will fail if we have two `[[Fichier:...]]` blocks in a sequence: http://regexr.com/3fhh6 – Dmitry Egorov Mar 16 '17 at 04:02
-2

Provided you my have at most one level of nested [[...]] (as your test data sample suggests), the inner regex pattern may comprise a sequence of either a string in double brackets (\[\[.*?\]\]) or anything but a closing bracket ([^]]):

\[\[Fichier:(?:\[\[.*?\]\]|[^]])*\]\]

Demo: https://regex101.com/r/Q7zQQt/1

For arbitrary number of nested levels the answer depends on regex flavour. You may find more details on this here: http://www.regular-expressions.info/balancing.html.

Dmitry Egorov
  • 9,542
  • 3
  • 22
  • 40