re = /\[ (?# match [ literally)
( (?# start capture group)
http (?# match http literally)
\S+ (?# match 1+ non-whitespace characters)
) (?# end capture group)
\s+ (?# match 1+ whitespace characters)
( (?# start capture group)
[^\]]+ (?# match 1+ non-] characters)
) (?# end capture group)
\] (?# match ] literally)
(?: (?# start non-capturing group)
\s+ (?# match 1+ whitespace characters)
from (?# match from literally)
(?: (?# start non-capturing group)
\s+ (?# match 1+ whitespace characters)
the (?# match the literally)
)? (?# end optional non-capturing group)
\s+ (?# match 1+ whitespace characters)
\[\[ (?# match [[ literally)
( (?# start capturing group)
.*? (?# lazily match 0+ characters)
) (?# end capturing group)
\]\] (?# match ]] literally)
)? (?# end optional non-caputring group)/x
str = '{{Wikibooks|Wikijunior:Countries A-Z|France}} {{Sister project links|France}} * [http://www.bbc.co.uk/news/world-europe-17298730 France] from the [[BBC News]] * [http://ucblibraries.colorado.edu/govpubs/for/france.htm France] at \'\'UCB Libraries GovPubs\'\' *{{dmoz|Regional/Europe/France}} * [http://www.britannica.com/EBchecked/topic/215768/France France] \'\'Encyclopædia Britannica\'\' entry * [http://europa.eu/about-eu/countries/member-countries/france/index_en.htm France] at the [[European Union|EU]] *{{Wikiatlas|France}} *{{osmrelation-inline|1403916}} * [http://www.ifs.du.edu/ifs/frm_CountryProfile.aspx?Country=FR Key Development Forecasts for France] from [[International Futures]] ;Economy *{{INSEE|National Institute of Statistics and Economic Studies}} * [http://stats.oecd.org/Index.aspx?QueryId=14594 OECD France statistics]'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html