import Foundation
let pattern = #"\[\[:fr:(?P<lien>[^:|[{}\n\]\|]+)\|(?P=lien)\]\]"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
[[:fr:Mille_Miglia_1932|Mille Miglia]]
[[:fr:wikt:demi-produit|demi-produit]] :
Amours Gauquié Pont Alexandre III Paris.jpg|Lampadaire "Ronde des Amours" de [[:fr:Henri Désiré Gauquié|Henri Désiré Gauquié]], [[Pont Alexandre III]] Kiosque...
- * [[:fr:Jean Dewasne|Jean Dewasne]]
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"[[\g<1>]]"#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
print(result)
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 Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression